kshowmailview.cpp

00001 /***************************************************************************
00002                           kshowmailview.cpp  -  description
00003                              -------------------
00004     begin                : Sat May  6 12:13:57 MEST 2000
00005     copyright            : (C) 2000-2001 by Eggert Ehmke
00006     email                : eggert.ehmke@berlin.de
00007 
00008      26 Sep 2002 - Allow for columns to be hidden. Allistar Melville
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 // include files for TQt
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 // application specific includes
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   //get application config object (kshowmailrc)
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   // sort account column
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   // sort number column
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, SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint &, int)),
00078                                                         SLOT (slotAccountContext(TQListViewItem*, const TQPoint &, int)));
00079        connect (m_pListAccounts, SIGNAL (clicked (TQListViewItem*, const TQPoint &, int)),
00080                                                         SLOT (slotAccountClicked(TQListViewItem*, const TQPoint &, int)));
00081        connect (m_pListMessages, SIGNAL (rightButtonClicked (TQListViewItem*, const TQPoint &, int)),
00082                                                         SLOT (slotMessageContext(TQListViewItem*, const TQPoint &, int)));
00083        connect (m_pListMessages, SIGNAL (doubleClicked (TQListViewItem*)),
00084                                                         SLOT (slotMessageDoubleClicked (TQListViewItem*)));
00085        connect (m_pListMessages, SIGNAL (clicked (TQListViewItem*)),
00086                                                         SLOT (slotMessageClicked (TQListViewItem*)));
00087 
00088   //read the geometry from the application config file
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   //read splitter geometry
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   // read layout of the list views
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 //     kdDebug () << "KshowmailView::saveOptions" << endl;
00117        config->setGroup("Display Options");
00118        //splitter
00119        TQValueList<int> size = sizes ();
00120        config->writeEntry ("sizeaccounts",  size [0]);
00121        config->writeEntry ("sizemessages",  size [1]);
00122        // layout
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     //get pointer to the main widget
00133     KShowMailApp* theApp = ( KShowMailApp * )parentWidget();
00134 
00135     //create and show popup menu
00136     TQWidget* w = theApp->factory()->container( "mail_context_popup", theApp );
00137     TQPopupMenu* popup = static_cast<TQPopupMenu*>( w );
00138     popup->exec( TQCursor::pos() );
00139 
00140     //select clicked item
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     //get pointer to the main widget
00150     KShowMailApp* theApp = ( KShowMailApp * )parentWidget();
00151 
00152     //create and show popup menu
00153     TQWidget* w = theApp->factory()->container( "account_context_popup", theApp );
00154     TQPopupMenu* popup = static_cast<TQPopupMenu*>( w );
00155     popup->exec( TQCursor::pos() );
00156 
00157     //select clicked item
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 //            m_pListMessages->setSelected (pItem, true);
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 //            m_pListMessages->setSelected (pItem, true);
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   //create item
00211   ShowListViewItem* item = new ShowListViewItem( m_pListMessages );
00212 
00213   //set content
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;     //entry of the config about show or hide column
00231   TQString ConfigEntrySavedWidth;  //entry of the config about saved width
00232   int DefaultWidth = 100;         //default width of the proceeded column
00233   bool DefaultDisplay = true;     //default show or hide of the proceeded column
00234 
00235   //set columns of the account list
00236   config->setGroup( CONFIG_GROUP_ACCOUNT_LIST );
00237   for( int column = 0; column <= 5; column++ )  //iterate over all columns
00238   {
00239     //get config entries and defaults of the proceeded column from the constants header
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     } //end select
00278 
00279     //get desired column state
00280     bool showColumn = config->readBoolEntry( ConfigEntryDisplay, DefaultDisplay );
00281 
00282     //get currently column state
00283     bool curShowed = m_pListAccounts->columnWidth( column ) > 0;
00284 
00285     if( showColumn )
00286     {
00287       //column will be shown
00288 
00289       if( !curShowed )
00290       {
00291         //the column is currently not be shown
00292 
00293         //get saved width or take default width
00294         int savedWidth = config->readNumEntry( ConfigEntrySavedWidth, DefaultWidth );
00295 
00296         //set column width
00297         m_pListAccounts->setColumnWidth( column, savedWidth );
00298       }
00299         //else: the column is currently shown; do nothing
00300     }
00301     else
00302     {
00303       //column will not be shown
00304 
00305       if( curShowed )
00306       {
00307         //the column is currently shown
00308 
00309         //save current width
00310         config->writeEntry( ConfigEntrySavedWidth, m_pListAccounts->columnWidth( column ) );
00311 
00312         //hide column
00313         m_pListAccounts->hideColumn( column );
00314       }
00315         //else: the column is already hidden; do nothing
00316     }
00317 
00318   } //end column loop
00319 
00320   //set columns of the message list
00321   config->setGroup( CONFIG_GROUP_MESSAGE_LIST );
00322   for( int column = 0; column <= 8; column++ )  //iterate over all columns
00323   {
00324     //get config entries and defaults of the proceeded column from the constants header
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     } //end select
00382 
00383     //get desired column state
00384     bool showColumn = config->readBoolEntry( ConfigEntryDisplay, DefaultDisplay );
00385 
00386     //get currently column state
00387     bool curShowed = m_pListMessages->columnWidth( column ) > 0;
00388 
00389     if( showColumn )
00390     {
00391       //column will be shown
00392 
00393       if( !curShowed )
00394       {
00395         //the column is currently not be shown
00396 
00397         //get saved width or take default width
00398         int savedWidth = config->readNumEntry( ConfigEntrySavedWidth, DefaultWidth );
00399 
00400         //set column width
00401         m_pListMessages->setColumnWidth( column, savedWidth );
00402       }
00403         //else: the column is currently shown; do nothing
00404     }
00405     else
00406     {
00407       //column will not be shown
00408 
00409       if( curShowed )
00410       {
00411         //the column is currently shown
00412 
00413         //save current width
00414         config->writeEntry( ConfigEntrySavedWidth, m_pListMessages->columnWidth( column ) );
00415 
00416         //hide column
00417         m_pListMessages->hideColumn( column );
00418       }
00419         //else: the column is already hidden; do nothing
00420     }
00421 
00422   } //end column loop
00423 
00424   //save current layout
00425   m_pListAccounts->saveLayout( config, CONFIG_GROUP_ACCOUNT_LIST );
00426   m_pListMessages->saveLayout( config, CONFIG_GROUP_MESSAGE_LIST );
00427   config->sync();
00428 }

Generated on Thu Jul 5 19:36:07 2007 for kshowmail by  doxygen 1.5.0