Skip to content

Commit

Permalink
flrn: add list_all_groups option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cigaes committed Dec 11, 2014
1 parent 9b12388 commit 0a11082
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 38 deletions.
5 changes: 5 additions & 0 deletions help/Help_3
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,11 @@ hist_file_name=<cha
lieu de sauvegarde de l'historique d'une session sur l'autre.
(d�faut : "")

list_all_groups=yes|no
demande la liste compl�te des groupes en une fois plut�t qu'un par
un�; utile si on est abonn� � plus d'environ un tiers des groupes et
si la latence est �lev�e.

max_group_size=<nombre>
permet de limiter la lecture des gros groupes par flrn aux messages
les plus r�cents. Lorsque cette valeur vaut -1, flrn charge tous
Expand Down
15 changes: 12 additions & 3 deletions src/flrn_inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3334,15 +3334,24 @@ int prochain_non_lu(int force_reste, Article_List **debut, int just_entered, int
/* -2 : erreur */
int prochain_newsgroup(Newsgroup_List **newgroup ) {
Newsgroup_List *mygroup=Newsgroup_courant, *last_mygroup;
int res;
int res, force_get = 1;

if (Options.list_all_groups) {
/* TODO Only refresh the whole list when a full cycle was done
without new messages. */
res = groups_get_all_unread();
if (res < 0)
return -2;
force_get = 0;
}

/* On teste d'abord strictement APRES Newsgroup_courant */
if (mygroup)
mygroup=mygroup->next;
while (mygroup) {
res=0;
if (!(mygroup->grp_flags & GROUP_UNSUBSCRIBED )) {
res=NoArt_non_lus(mygroup,1);
res = NoArt_non_lus(mygroup, force_get);
if (res>0) break;
}
last_mygroup=mygroup;
Expand All @@ -3360,7 +3369,7 @@ int prochain_newsgroup(Newsgroup_List **newgroup ) {
while (mygroup!=Newsgroup_courant) {
res=0;
if (!(mygroup->grp_flags & GROUP_UNSUBSCRIBED)) {
res=NoArt_non_lus(mygroup,1);
res = NoArt_non_lus(mygroup, force_get);
if (res>0) break;
}
last_mygroup=mygroup;
Expand Down
115 changes: 80 additions & 35 deletions src/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,37 +812,11 @@ int cherche_newnews() {
return 0;
}

/* Renvoie le nombre estimé d'articles non lus dans group */
/* returne -1 en cas d'erreur de lecture. */
/* -2 si le newsgroup n'existe pas (glup !) */
int NoArt_non_lus(Newsgroup_List *group, int force_check) {
int i, res, code, non_lus, max, min;
Range_List *actuel;
char *buf;
int rc;
char *trad;

if ((group->not_read!=-1) && (!force_check)) return group->not_read;
/* On envoie un list active au serveur */
buf=safe_malloc((MAX_NEWSGROUP_LEN+10)*sizeof(char));
strcpy(buf, "active ");
rc=conversion_to_utf8(group->name,&trad,0,(size_t)(-1));
strcat(buf, trad);
if (rc==0) free(trad);
res=write_command(CMD_LIST, 1, &buf);
free(buf);
if (res<3) return -1;

code=return_code();
if ((code<0) || (code>400)) return -1;

res=read_server_for_list(tcp_line_read, 1, MAX_READ_SIZE-1);
if (res<0) return -1;
if (tcp_line_read[1]=='\r') {
return -2; /* Pas glop, tout ca */
}
/* Normalement, une ligne de lecture suffit amplement */
buf=strchr(tcp_line_read,' ');
static void
list_active_parse_unread(Newsgroup_List *group, char *buf)
{
int i, min, max, non_lus;
Range_List *actuel;
/* SURTOUT ne pas changer group->max et group->min si le groupe est déjà */
/* connu : ça fait planter les changement de groupes qui suivent... */
max=strtol(buf,&buf,10);
Expand All @@ -863,11 +837,9 @@ int NoArt_non_lus(Newsgroup_List *group, int force_check) {
break;
}
group->grp_flags |= GROUP_MODE_TESTED;
discard_server(); /* Si il y a plusieurs newsgroups, BEURK */

non_lus=max-min+1;
if (group->max==0) { return 0; /* le groupe est vide */
}
if (group->max==0) return;
actuel=group->read;
while (actuel) {
for (i=0; i<RANGE_TABLE_SIZE; i++) {
Expand All @@ -883,7 +855,80 @@ int NoArt_non_lus(Newsgroup_List *group, int force_check) {
else group->virtual_in_not_read=0;
group->not_read=non_lus;

return non_lus;
}

int
groups_get_all_unread(void)
{
Newsgroup_List *group;
int res, code;
char *tail;

for (group = Newsgroup_deb; group != NULL; group = group->next)
group->not_read = -1;

res = write_command(CMD_LIST, 0, NULL);
if (res < 3)
return -1;
code = return_code();
if (code < 0 || code > 400)
return -1;

while (1) {
res = read_server_for_list(tcp_line_read, 1, MAX_READ_SIZE - 1);
if (res < 3)
return -1;
if (tcp_line_read[0] == '.')
break;
tail = strchr(tcp_line_read, ' ');
if (tail == NULL) {
fprintf(stderr, "groups_get_all_unread: strange line '%s'\n",
tcp_line_read);
continue;
}
*(tail++) = 0;
for (group = Newsgroup_deb; group != NULL; group = group->next)
if (strcmp(group->name, tcp_line_read) == 0)
break;
if (group != NULL)
list_active_parse_unread(group, tail);
}
return 0;
}

/* Renvoie le nombre estimé d'articles non lus dans group */
/* returne -1 en cas d'erreur de lecture. */
/* -2 si le newsgroup n'existe pas (glup !) */
int NoArt_non_lus(Newsgroup_List *group, int force_check) {
int i, res, code;
char *buf;
int rc;
char *trad;

if ((group->not_read!=-1) && (!force_check)) return group->not_read;
/* On envoie un list active au serveur */
buf=safe_malloc((MAX_NEWSGROUP_LEN+10)*sizeof(char));
strcpy(buf, "active ");
rc=conversion_to_utf8(group->name,&trad,0,(size_t)(-1));
strcat(buf, trad);
if (rc==0) free(trad);
res=write_command(CMD_LIST, 1, &buf);
free(buf);
if (res<3) return -1;

code=return_code();
if ((code<0) || (code>400)) return -1;

res=read_server_for_list(tcp_line_read, 1, MAX_READ_SIZE-1);
if (res<0) return -1;
if (tcp_line_read[1]=='\r') {
return -2; /* Pas glop, tout ca */
}
/* Normalement, une ligne de lecture suffit amplement */
buf=strchr(tcp_line_read,' ');
list_active_parse_unread(group, buf);
discard_server(); /* Si il y a plusieurs newsgroups, BEURK */
return group->not_read;
}

void test_readonly(Newsgroup_List *groupe) {
Expand Down
1 change: 1 addition & 0 deletions src/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extern Newsgroup_List *cherche_newsgroup_re (flrn_char * /*name*/,
extern Liste_Menu *menu_newsgroup_re (flrn_char * /*name*/, regex_t /*reg*/,
int /*avec_reg*/);
extern void zap_newsgroup(Newsgroup_List * /*group*/);
extern int groups_get_all_unread(void);
extern int NoArt_non_lus(Newsgroup_List * /*group*/, int);
extern int cherche_newnews(void);
extern void add_read_article(Newsgroup_List * /*group*/, int /*numero*/);
Expand Down
2 changes: 2 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct Option_struct {
flrn_char *default_domain;
#endif
int max_group_size;
int list_all_groups;
flrn_char *alternate;
};

Expand Down Expand Up @@ -270,6 +271,7 @@ static struct {
MAKE_OPT(include_in_edit,N_("Lorsque auto_edit est défini, inclut automatiquement le message d'origine.")),
MAKE_STRING_OPT(index_string,N_("Caractères précédents un quote.")),
MAKE_STRING_OPT(kill_file_name,N_("Nom du fichier de kill utilisé.")),
MAKE_OPT(list_all_groups,N_("Liste tous les groupes d'un coup.")),
MAKE_INTEGER_OPT(max_group_size,N_("Taille maximum de gestion d'un groupe.")),
MAKE_OPT(ordered_summary,N_("Ordonne les résumés suivant leur numéro.")),
MAKE_OPT(parse_from,N_("Affiche le \"Auteur:\" et le \"Réponse à:\" plus forum-like.")),
Expand Down

0 comments on commit 0a11082

Please sign in to comment.