~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

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
#ifndef __KMAIL__MANAGESIEVESCRIPTSDIALOG_H__
#define __KMAIL__MANAGESIEVESCRIPTSDIALOG_H__

#include <kdialog.h>
#include <kurl.h>

#include <QMap>

class QButtonGroup;
class QTreeWidgetItem;

namespace KMail {

class SieveJob;
class SieveEditor;
class TreeWidgetWithContextMenu;

class ManageSieveScriptsDialog : public KDialog {
  Q_OBJECT
public:
  explicit ManageSieveScriptsDialog( QWidget * parent=0, const char * name=0 );
  ~ManageSieveScriptsDialog();

private slots:
  void slotRefresh();
  void slotItem( KMail::SieveJob *, const QString &, bool );
  void slotResult( KMail::SieveJob *, bool, const QString &, bool );
  void slotContextMenuRequested( QTreeWidgetItem*, QPoint position );
  void slotDoubleClicked( QTreeWidgetItem* );
  void slotSelectionChanged();
  void slotNewScript();
  void slotEditScript();
  void slotDeleteScript();
  void slotDeactivateScript();
  void slotGetResult( KMail::SieveJob *, bool, const QString &, bool );
  void slotPutResult( KMail::SieveJob *, bool );
  void slotSieveEditorOkClicked();
  void slotSieveEditorCancelClicked();
private:
  void killAllJobs();
  void changeActiveScript( QTreeWidgetItem*, bool activate = true );

  /**
   * Adds a radio button to the specified item.
   */
  void addRadioButton( QTreeWidgetItem *item, const QString &text );

  /**
   * Turns the radio button for the specified item on or off.
   */
  void setRadioButtonState( QTreeWidgetItem *item, bool checked );

  /**
   * @return whether the specified item's radio button is checked or not
   */
  bool isRadioButtonChecked( QTreeWidgetItem *item ) const;

  /**
   * @return the text of the item. This is needed because the text is stored in the
   *         radio button, and not in the tree widget item.
   */
  QString itemText( QTreeWidgetItem *item ) const;

  /**
   * @return true if this tree widget item represents a sieve script, i.e. this item
   *              is not an account and not an error message.
   */
  bool isFileNameItem( QTreeWidgetItem *item ) const;

  /**
   * Remove everything from the tree widget and clear all caches.
   */
  void clear();

private:
  TreeWidgetWithContextMenu* mListView;
  QTreeWidgetItem *mContextMenuItem;
  SieveEditor * mSieveEditor;
  QMap<KMail::SieveJob*,QTreeWidgetItem*> mJobs;
  QMap<QTreeWidgetItem*,KUrl> mUrls;

  // Maps top-level items to their child which has the radio button selection
  QMap<QTreeWidgetItem*,QTreeWidgetItem*> mSelectedItems;

  // Maps the top-level tree widget items (the accounts) to a button group.
  // The button group is used for the radio buttons of the child items.
  QMap<QTreeWidgetItem*,QButtonGroup*> mButtonGroups;

  KUrl mCurrentURL;
  bool mWasActive : 1;
};

}

#endif /* __KMAIL__MANAGESIEVESCRIPTSDIALOG_H__ */