00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <ntqprinter.h>
00022 #include <ntqpainter.h>
00023 #include <ntqmessagebox.h>
00024 #include <ntqkeycode.h>
00025 #include <ntqvaluelist.h>
00026
00027 #include <kstandarddirs.h>
00028 #include <tdelocale.h>
00029 #include <kdebug.h>
00030
00031
00032 #include "kshowmailview.h"
00033 #include "kshowmaildoc.h"
00034 #include "kshowmail.h"
00035
00036 KshowmailView::KshowmailView(TQWidget *parent, const char *name):
00037 TQSplitter(Vertical, parent, name)
00038 {
00039
00040 config = TDEApplication::kApplication()->config();
00041
00042 m_pixOk = new TQPixmap (::locate ("data", "kshowmail/pics/ok.png"));
00043
00044 m_pListAccounts = new TDEListView (this, "accounts");
00045 m_pListMessages = new TDEListView (this, "messages");
00046 setBackgroundMode(PaletteBase);
00047
00048 m_pListAccounts->setSelectionMode (TQListView::Extended);
00049 m_pListAccounts->setAllColumnsShowFocus (true);
00050
00051 m_pListAccounts->setSorting (1);
00052 m_pListAccounts->setShowSortIndicator (true);
00053 m_pListAccounts->addColumn (i18n("Active"), DEFAULT_WIDTH_ACCOUNT_ACTIVE );
00054 m_pListAccounts->addColumn (i18n("Account"), DEFAULT_WIDTH_ACCOUNT_ACCOUNT );
00055 m_pListAccounts->addColumn (i18n("Server"), DEFAULT_WIDTH_ACCOUNT_SERVER );
00056 m_pListAccounts->addColumn (i18n("User"), DEFAULT_WIDTH_ACCOUNT_USER );
00057 m_pListAccounts->addColumn (i18n("Messages"), DEFAULT_WIDTH_ACCOUNT_MESSAGES );
00058 m_pListAccounts->addColumn (i18n("Size"), DEFAULT_WIDTH_ACCOUNT_SIZE );
00059
00060 m_pListMessages->setSelectionMode (TQListView::Extended);
00061 m_pListMessages->setAllColumnsShowFocus (true);
00062
00063 m_pListMessages->setSorting (ShowListViewItem::_colNumber);
00064 m_pListMessages->setShowSortIndicator (true);
00065 setFocusPolicy (TQWidget::StrongFocus);
00066
00067 m_pListMessages->addColumn (i18n("Number"), DEFAULT_WIDTH_MESSAGE_NUMBER );
00068 m_pListMessages->addColumn (i18n("Account"), DEFAULT_WIDTH_MESSAGE_ACCOUNT );
00069 m_pListMessages->addColumn (i18n("From"), DEFAULT_WIDTH_MESSAGE_FROM );
00070 m_pListMessages->addColumn (i18n("To"), DEFAULT_WIDTH_MESSAGE_TO );
00071 m_pListMessages->addColumn (i18n("Subject"), DEFAULT_WIDTH_MESSAGE_SUBJECT );
00072 m_pListMessages->addColumn (i18n("Date"), DEFAULT_WIDTH_MESSAGE_DATE );
00073 m_pListMessages->addColumn (i18n("Size"), DEFAULT_WIDTH_MESSAGE_SIZE );
00074 m_pListMessages->addColumn (i18n("Content"), DEFAULT_WIDTH_MESSAGE_CONTENT );
00075 m_pListMessages->addColumn (i18n("State"), DEFAULT_WIDTH_MESSAGE_STATE );
00076
00077 connect (m_pListAccounts, TQ_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint &, int)),
00078 TQ_SLOT (slotAccountContext(TQListViewItem*, const TQPoint &, int)));
00079 connect (m_pListAccounts, TQ_SIGNAL (clicked (TQListViewItem*, const TQPoint &, int)),
00080 TQ_SLOT (slotAccountClicked(TQListViewItem*, const TQPoint &, int)));
00081 connect (m_pListMessages, TQ_SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint &, int)),
00082 TQ_SLOT (slotMessageContext(TQListViewItem*, const TQPoint &, int)));
00083 connect (m_pListMessages, TQ_SIGNAL (doubleClicked (TQListViewItem*)),
00084 TQ_SLOT (slotMessageDoubleClicked (TQListViewItem*)));
00085 connect (m_pListMessages, TQ_SIGNAL (clicked (TQListViewItem*)),
00086 TQ_SLOT (slotMessageClicked (TQListViewItem*)));
00087
00088
00089 readOptions();
00090
00091
00092 }
00093
00094 KshowmailView::~KshowmailView()
00095 {
00096 delete m_pListAccounts;
00097 delete m_pListMessages;
00098 }
00099
00100 void KshowmailView::readOptions()
00101 {
00102
00103 config->setGroup ("Display Options");
00104 TQValueList<int> size;
00105 size.append (config->readNumEntry ("sizeaccounts", 40));
00106 size.append (config->readNumEntry ("sizemessages", 50));
00107 setSizes (size);
00108
00109
00110 m_pListAccounts->restoreLayout( config, CONFIG_GROUP_ACCOUNT_LIST );
00111 m_pListMessages->restoreLayout( config, CONFIG_GROUP_MESSAGE_LIST );
00112 }
00113
00114 void KshowmailView::saveOptions (TDEConfig* config)
00115 {
00116
00117 config->setGroup("Display Options");
00118
00119 TQValueList<int> size = sizes ();
00120 config->writeEntry ("sizeaccounts", size [0]);
00121 config->writeEntry ("sizemessages", size [1]);
00122
00123 m_pListAccounts->saveLayout ( config, CONFIG_GROUP_ACCOUNT_LIST );
00124 m_pListMessages->saveLayout (config, CONFIG_GROUP_MESSAGE_LIST );
00125 }
00126
00127
00128 void KshowmailView::slotMessageContext( TQListViewItem* pItem, const TQPoint&, int )
00129 {
00130 if( pItem != NULL )
00131 {
00132
00133 KShowMailApp* theApp = ( KShowMailApp * )parentWidget();
00134
00135
00136 TQWidget* w = theApp->factory()->container( "mail_context_popup", theApp );
00137 TQPopupMenu* popup = static_cast<TQPopupMenu*>( w );
00138 popup->exec( TQCursor::pos() );
00139
00140
00141 m_pListMessages->setSelected (pItem, true);
00142 }
00143 }
00144
00145 void KshowmailView::slotAccountContext( TQListViewItem* pItem, const TQPoint&, int )
00146 {
00147 if ( pItem != NULL )
00148 {
00149
00150 KShowMailApp* theApp = ( KShowMailApp * )parentWidget();
00151
00152
00153 TQWidget* w = theApp->factory()->container( "account_context_popup", theApp );
00154 TQPopupMenu* popup = static_cast<TQPopupMenu*>( w );
00155 popup->exec( TQCursor::pos() );
00156
00157
00158 m_pListAccounts->setSelected( pItem, true );
00159 }
00160 }
00161
00162 void KshowmailView::slotAccountClicked (TQListViewItem* pItem, const TQPoint&, int col)
00163 {
00164 if (col == 0)
00165 {
00166 KShowMailApp *theApp=(KShowMailApp *) parentWidget();
00167 ConfigElem* pElem = theApp->m_ConfigList.getSelectedAccount();
00168 if( pElem != NULL )
00169 {
00170 pElem->setActive( !pElem->isActive() );
00171 if (pElem->isActive() )
00172 pItem->setPixmap (0, *m_pixOk);
00173 else
00174 pItem->setPixmap (0, 0);
00175 emit signalActiveChanged ();
00176 }
00177 }
00178 }
00179
00180 void KshowmailView::slotMessageDoubleClicked (TQListViewItem* pItem)
00181 {
00182 if (pItem)
00183 {
00184
00185
00186 KShowMailApp *theApp=(KShowMailApp *) parentWidget();
00187 theApp->slotShowHeader ();
00188 }
00189 }
00190
00191 void KshowmailView::slotMessageClicked (TQListViewItem* pItem)
00192 {
00193 kdDebug () << "slotMessageClicked" << endl;
00194 if (pItem)
00195 {
00196
00197
00198 KShowMailApp *theApp=(KShowMailApp *) parentWidget();
00199 theApp->delayNextRefresh();
00200 }
00201 }
00202
00203 void KshowmailView::clearMailListView( )
00204 {
00205 m_pListMessages->clear();
00206 }
00207
00208 ShowListViewItem* KshowmailView::insertMail( TQString& number, TQString& account, TQString& from, TQString& to, TQString& subject, TQString& date, TQString& size, TQString& content, TQString& state, TQString& time )
00209 {
00210
00211 ShowListViewItem* item = new ShowListViewItem( m_pListMessages );
00212
00213
00214 item->setNumber( number );
00215 item->setAccount( account );
00216 item->setFrom( from );
00217 item->setTo( to );
00218 item->setSubject( subject );
00219 item->setDate( date );
00220 item->setSize( size );
00221 item->setContent( content );
00222 item->setState( state );
00223 item->setTime( time );
00224
00225 return item;
00226 }
00227
00228 void KshowmailView::refreshSetup( )
00229 {
00230 TQString ConfigEntryDisplay;
00231 TQString ConfigEntrySavedWidth;
00232 int DefaultWidth = 100;
00233 bool DefaultDisplay = true;
00234
00235
00236 config->setGroup( CONFIG_GROUP_ACCOUNT_LIST );
00237 for( int column = 0; column <= 5; column++ )
00238 {
00239
00240 switch( column )
00241 {
00242 case 0: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_ACTIVE;
00243 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_ACTIVE;
00244 DefaultWidth = DEFAULT_WIDTH_ACCOUNT_ACTIVE;
00245 DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_ACTIVE;
00246 break;
00247
00248 case 1: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_ACCOUNT;
00249 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_ACCOUNT;
00250 DefaultWidth = DEFAULT_WIDTH_ACCOUNT_ACCOUNT;
00251 DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_ACCOUNT;
00252 break;
00253
00254 case 2: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_SERVER;
00255 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_SERVER;
00256 DefaultWidth = DEFAULT_WIDTH_ACCOUNT_SERVER;
00257 DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_SERVER;
00258 break;
00259
00260 case 3: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_USER;
00261 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_USER;
00262 DefaultWidth = DEFAULT_WIDTH_ACCOUNT_USER;
00263 DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_USER;
00264 break;
00265
00266 case 4: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_MESSAGES;
00267 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_MESSAGES;
00268 DefaultWidth = DEFAULT_WIDTH_ACCOUNT_MESSAGES;
00269 DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_MESSAGES;
00270 break;
00271
00272 case 5: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_SIZE;
00273 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_SIZE;
00274 DefaultWidth = DEFAULT_WIDTH_ACCOUNT_SIZE;
00275 DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_SIZE;
00276 break;
00277 }
00278
00279
00280 bool showColumn = config->readBoolEntry( ConfigEntryDisplay, DefaultDisplay );
00281
00282
00283 bool curShowed = m_pListAccounts->columnWidth( column ) > 0;
00284
00285 if( showColumn )
00286 {
00287
00288
00289 if( !curShowed )
00290 {
00291
00292
00293
00294 int savedWidth = config->readNumEntry( ConfigEntrySavedWidth, DefaultWidth );
00295
00296
00297 m_pListAccounts->setColumnWidth( column, savedWidth );
00298 }
00299
00300 }
00301 else
00302 {
00303
00304
00305 if( curShowed )
00306 {
00307
00308
00309
00310 config->writeEntry( ConfigEntrySavedWidth, m_pListAccounts->columnWidth( column ) );
00311
00312
00313 m_pListAccounts->hideColumn( column );
00314 }
00315
00316 }
00317
00318 }
00319
00320
00321 config->setGroup( CONFIG_GROUP_MESSAGE_LIST );
00322 for( int column = 0; column <= 8; column++ )
00323 {
00324
00325 switch( column )
00326 {
00327 case 0: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_NUMBER;
00328 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_NUMBER;
00329 DefaultWidth = DEFAULT_WIDTH_MESSAGE_NUMBER;
00330 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_NUMBER;
00331 break;
00332
00333 case 1: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_ACCOUNT;
00334 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_ACCOUNT;
00335 DefaultWidth = DEFAULT_WIDTH_MESSAGE_ACCOUNT;
00336 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_ACCOUNT;
00337 break;
00338
00339 case 2: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_FROM;
00340 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_FROM;
00341 DefaultWidth = DEFAULT_WIDTH_MESSAGE_FROM;
00342 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_FROM;
00343 break;
00344
00345 case 3: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_TO;
00346 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_TO;
00347 DefaultWidth = DEFAULT_WIDTH_MESSAGE_TO;
00348 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_TO;
00349 break;
00350
00351 case 4: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_SUBJECT;
00352 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_SUBJECT;
00353 DefaultWidth = DEFAULT_WIDTH_MESSAGE_SUBJECT;
00354 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_SUBJECT;
00355 break;
00356
00357 case 5: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_DATE;
00358 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_DATE;
00359 DefaultWidth = DEFAULT_WIDTH_MESSAGE_DATE;
00360 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_DATE;
00361 break;
00362
00363 case 6: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_SIZE;
00364 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_SIZE;
00365 DefaultWidth = DEFAULT_WIDTH_MESSAGE_SIZE;
00366 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_SIZE;
00367 break;
00368
00369 case 7: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_CONTENT;
00370 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_CONTENT;
00371 DefaultWidth = DEFAULT_WIDTH_MESSAGE_CONTENT;
00372 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_CONTENT;
00373 break;
00374
00375 case 8: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_STATE;
00376 ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_STATE;
00377 DefaultWidth = DEFAULT_WIDTH_MESSAGE_STATE;
00378 DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_STATE;
00379 break;
00380
00381 }
00382
00383
00384 bool showColumn = config->readBoolEntry( ConfigEntryDisplay, DefaultDisplay );
00385
00386
00387 bool curShowed = m_pListMessages->columnWidth( column ) > 0;
00388
00389 if( showColumn )
00390 {
00391
00392
00393 if( !curShowed )
00394 {
00395
00396
00397
00398 int savedWidth = config->readNumEntry( ConfigEntrySavedWidth, DefaultWidth );
00399
00400
00401 m_pListMessages->setColumnWidth( column, savedWidth );
00402 }
00403
00404 }
00405 else
00406 {
00407
00408
00409 if( curShowed )
00410 {
00411
00412
00413
00414 config->writeEntry( ConfigEntrySavedWidth, m_pListMessages->columnWidth( column ) );
00415
00416
00417 m_pListMessages->hideColumn( column );
00418 }
00419
00420 }
00421
00422 }
00423
00424
00425 m_pListAccounts->saveLayout( config, CONFIG_GROUP_ACCOUNT_LIST );
00426 m_pListMessages->saveLayout( config, CONFIG_GROUP_MESSAGE_LIST );
00427 config->sync();
00428 }