kmail

kmfolderseldlg.cpp
1 // kmfolderseldlg.cpp
2 
3 #include <config.h>
4 #include "kmfolderseldlg.h"
5 #include "kmfolder.h"
6 #include "kmmainwidget.h"
7 #include "globalsettings.h"
8 
9 #include <kdebug.h>
10 #include <klineedit.h>
11 #include <tdepopupmenu.h>
12 #include <kiconloader.h>
13 
14 #include <tqlayout.h>
15 #include <tqtoolbutton.h>
16 #include <tqlabel.h>
17 
18 
19 using namespace KMail;
20 //-----------------------------------------------------------------------------
21 KMFolderSelDlg::KMFolderSelDlg( KMMainWidget * parent, const TQString& caption,
22  bool mustBeReadWrite, bool useGlobalSettings )
23  : KDialogBase( parent, "folder dialog", true, caption,
24  Ok|Cancel|User1, Ok, true,
25  KGuiItem(i18n("&New Subfolder..."), "folder-new",
26  i18n("Create a new subfolder under the currently selected folder"))
27  ), // mainwin as parent, modal
28  mUseGlobalSettings( useGlobalSettings )
29 {
30  KMFolderTree * ft = parent->folderTree();
31  assert( ft );
32 
33  TQString preSelection = mUseGlobalSettings ?
34  GlobalSettings::self()->lastSelectedFolder() : TQString();
35  TQWidget * container = makeVBoxMainWidget();
36  new TQLabel( i18n("You can start typing to filter the list of folders"), container );
37  mTreeView = new KMail::SimpleFolderTree( container, ft,
38  preSelection, mustBeReadWrite );
39  init();
40 }
41 
42 //----------------------------------------------------------------------------
43 KMFolderSelDlg::KMFolderSelDlg( TQWidget * parent, KMFolderTree * tree,
44  const TQString& caption, bool mustBeReadWrite, bool useGlobalSettings )
45  : KDialogBase( parent, "folder dialog", true, caption,
46  Ok|Cancel|User1, Ok, true,
47  KGuiItem(i18n("&New Subfolder..."), "folder-new",
48  i18n("Create a new subfolder under the currently selected folder"))
49  ), // mainwin as parent, modal
50  mUseGlobalSettings( useGlobalSettings )
51 {
52  TQString preSelection = mUseGlobalSettings ?
53  GlobalSettings::self()->lastSelectedFolder() : TQString();
54  TQWidget * container = makeVBoxMainWidget();
55  new TQLabel( i18n("You can start typing to filter the list of folders"), container );
56  mTreeView = new KMail::SimpleFolderTree( container, tree,
57  preSelection, mustBeReadWrite );
58  init();
59 }
60 
61 //-----------------------------------------------------------------------------
62 void KMFolderSelDlg::init()
63 {
64  mTreeView->setFocus();
65  connect( mTreeView, TQ_SIGNAL( doubleClicked( TQListViewItem*, const TQPoint&, int ) ),
66  this, TQ_SLOT( slotSelect() ) );
67  connect( mTreeView, TQ_SIGNAL( selectionChanged() ),
68  this, TQ_SLOT( slotUpdateBtnStatus() ) );
69 
70  readConfig();
71 }
72 
73 //-----------------------------------------------------------------------------
74 KMFolderSelDlg::~KMFolderSelDlg()
75 {
76  const KMFolder * cur = folder();
77  if ( cur && mUseGlobalSettings ) {
78  GlobalSettings::self()->setLastSelectedFolder( cur->idString() );
79  }
80 
81  writeConfig();
82 }
83 
84 
85 //-----------------------------------------------------------------------------
86 KMFolder * KMFolderSelDlg::folder( void )
87 {
88  return ( KMFolder * ) mTreeView->folder();
89 }
90 
91 //-----------------------------------------------------------------------------
92 void KMFolderSelDlg::setFolder( KMFolder* folder )
93 {
94  mTreeView->setFolder( folder );
95 }
96 
97 //-----------------------------------------------------------------------------
98 void KMFolderSelDlg::slotSelect()
99 {
100  accept();
101 }
102 
103 //-----------------------------------------------------------------------------
104 void KMFolderSelDlg::slotUser1()
105 {
106  mTreeView->addChildFolder();
107 }
108 
109 //-----------------------------------------------------------------------------
110 void KMFolderSelDlg::slotUpdateBtnStatus()
111 {
112  enableButton( User1, folder() &&
113  ( !folder()->noContent() && !folder()->noChildren() ) );
114 }
115 
116 //-----------------------------------------------------------------------------
117 void KMFolderSelDlg::setFlags( bool mustBeReadWrite, bool showOutbox,
118  bool showImapFolders )
119 {
120  mTreeView->reload( mustBeReadWrite, showOutbox, showImapFolders );
121 }
122 
123 void KMFolderSelDlg::readConfig()
124 {
125  TDEConfig *config = TDEGlobal::config();
126  config->setGroup( "FolderSelectionDialog" );
127 
128  TQSize size = config->readSizeEntry( "Size" );
129  if ( !size.isEmpty() ) resize( size );
130  else resize( 500, 300 );
131 
132  TQValueList<int> widths = config->readIntListEntry( "ColumnWidths" );
133  if ( !widths.isEmpty() ) {
134  mTreeView->setColumnWidth(mTreeView->folderColumn(), widths[0]);
135  mTreeView->setColumnWidth(mTreeView->pathColumn(), widths[1]);
136  }
137  else {
138  int colWidth = width() / 2;
139  mTreeView->setColumnWidth(mTreeView->folderColumn(), colWidth);
140  mTreeView->setColumnWidth(mTreeView->pathColumn(), colWidth);
141  }
142 }
143 
144 void KMFolderSelDlg::writeConfig()
145 {
146  TDEConfig *config = TDEGlobal::config();
147  config->setGroup( "FolderSelectionDialog" );
148  config->writeEntry( "Size", size() );
149 
150  TQValueList<int> widths;
151  widths.push_back(mTreeView->columnWidth(mTreeView->folderColumn()));
152  widths.push_back(mTreeView->columnWidth(mTreeView->pathColumn()));
153  config->writeEntry( "ColumnWidths", widths );
154 }
155 
156 
157 #include "kmfolderseldlg.moc"
Mail folder.
Definition: kmfolder.h:69
TQString idString() const
Returns a string that can be used to identify this folder.
Definition: kmfolder.cpp:705
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
folderdiaquotatab.h
Definition: aboutdata.cpp:40