summaryrefslogtreecommitdiffstats
path: root/knode/kngroupmanager.h
blob: e357383016eb6e21eeb4433ba09988aa99f0a2f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
    KNode, the KDE newsreader
    Copyright (c) 1999-2005 the KNode authors.
    See file AUTHORS for details

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/

#ifndef KNGROUPMANAGER_H
#define KNGROUPMANAGER_H

#include <tqobject.h>
#include <tqsortedlist.h>

#include "knjobdata.h"
#include "kngroup.h"

class KNNntpAccount;
class KNProtocolClient;
class KNServerInfo;
class KNArticleManager;
class KNCleanUp;


//=================================================================================

/** helper classes for the group selection dialog
    contains info about a newsgroup (name, description) */

class KNGroupInfo {

  public:

    KNGroupInfo();
    KNGroupInfo(const TQString &n_ame, const TQString &d_escription, bool n_ewGroup=false, bool s_ubscribed=false, KNGroup::Status s_tatus=KNGroup::unknown );
    ~KNGroupInfo();

    /** group names will be utf-8 encoded in the future... */
    TQString name,description;
    bool newGroup, subscribed;
    KNGroup::Status status;

    bool operator== (const KNGroupInfo &gi2);
    bool operator< (const KNGroupInfo &gi2);
};


class KNGroupListData : public KNJobItem {

  public:
    KNGroupListData();
    ~KNGroupListData();

    bool readIn(KNProtocolClient *client=0);
    bool writeOut();
    void merge(TQSortedList<KNGroupInfo>* newGroups);

    TQSortedList<KNGroupInfo>* extractList();

    TQStringList subscribed;
    TQString path;
    TQSortedList<KNGroupInfo> *groups;
    TQDate fetchSince;
    bool getDescriptions;
    TQTextCodec *codecForDescriptions;

};

//===============================================================================


class KNGroupManager : public TQObject , public KNJobConsumer {

  Q_OBJECT
  

  public:

    KNGroupManager(TQObject * parent=0, const char * name=0);
    ~KNGroupManager();

    // group access
    void loadGroups(KNNntpAccount *a);
    void getSubscribed(KNNntpAccount *a, TQStringList &l);
    TQValueList<KNGroup*> groupsOfAccount( KNNntpAccount *a );

    bool loadHeaders(KNGroup *g);
    bool unloadHeaders(KNGroup *g, bool force=true);

    KNGroup* group(const TQString &gName, const KNServerInfo *s);
    KNGroup* firstGroupOfAccount(const KNServerInfo *s);
    KNGroup* currentGroup() const              { return c_urrentGroup; }
    bool hasCurrentGroup() const               { return (c_urrentGroup!=0); }
    void setCurrentGroup(KNGroup *g);

    // group handling
    void showGroupDialog(KNNntpAccount *a, TQWidget *parent=0);
    void subscribeGroup(const KNGroupInfo *gi, KNNntpAccount *a);
    bool unsubscribeGroup(KNGroup *g=0);
    void showGroupProperties(KNGroup *g=0);
    void expireGroupNow(KNGroup *g=0);
    void reorganizeGroup(KNGroup *g=0);

    void checkGroupForNewHeaders(KNGroup *g=0);
    void checkAll(KNNntpAccount *a, bool silent=false);

    void expireAll(KNCleanUp *cup);
    void expireAll(KNNntpAccount *a);
    void syncGroups();

  public slots:
    /** load group list from disk (if this fails: ask user if we should fetch the list) */
    void slotLoadGroupList(KNNntpAccount *a);
    /** fetch group list from server */
    void slotFetchGroupList(KNNntpAccount *a);
    /** check for new groups (created after the given date) */
    void slotCheckForNewGroups(KNNntpAccount *a, TQDate date);

  protected:
    /** reimplemented from @ref KNJobConsumer */
    void processJob(KNJobData *j);
    TQValueList<KNGroup*> mGroupList;
    KNGroup *c_urrentGroup;
    KNArticleManager *a_rticleMgr;

  signals:
    void newListReady(KNGroupListData* d);

    void groupAdded(KNGroup* g);
    void groupRemoved(KNGroup* g);
    void groupUpdated(KNGroup* g);

};



#endif