From b888c7edb54e483ec0e3c2e2ce0eafd73acdcc65 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 24 Jul 2013 15:57:00 -0500 Subject: Initial import from kshowmail 3.3.1 sources --- kshowmail/kshowmailview.cpp | 449 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 449 insertions(+) create mode 100644 kshowmail/kshowmailview.cpp (limited to 'kshowmail/kshowmailview.cpp') diff --git a/kshowmail/kshowmailview.cpp b/kshowmail/kshowmailview.cpp new file mode 100644 index 0000000..d7fb3a5 --- /dev/null +++ b/kshowmail/kshowmailview.cpp @@ -0,0 +1,449 @@ +/*************************************************************************** + kshowmailview.cpp - description + ------------------- + begin : Sat May 6 12:13:57 MEST 2000 + copyright : (C) 2000-2001 by Eggert Ehmke + email : eggert.ehmke@berlin.de + + 26 Sep 2002 - Allow for columns to be hidden. Allistar Melville + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// include files for Qt +#include +#include +#include +#include +#include + +#include +#include +#include + +// application specific includes +#include "kshowmailview.h" +#include "kshowmaildoc.h" +#include "kshowmail.h" + +KshowmailView::KshowmailView(QWidget *parent, const char *name): + QSplitter(Vertical, parent, name) +{ + setBackgroundMode( PaletteBase ); + setFocusPolicy( QWidget::StrongFocus ); + + //get application config object (kshowmailrc) + config = KApplication::kApplication()->config(); + + //load active pic for the account list + m_pixOk = new QPixmap( ::locate( "data", "kshowmail/pics/ok.png" ) ); + + //create account list + m_pListAccounts = new KListView( this, "accounts" ); + m_pListAccounts->setSelectionMode( QListView::Extended ); + m_pListAccounts->setSorting( 1 ); // sort account column + m_pListAccounts->setShowSortIndicator( true ); + m_pListAccounts->addColumn( i18n( "Active" ), DEFAULT_WIDTH_ACCOUNT_ACTIVE ); + m_pListAccounts->addColumn( i18n( "Account" ), DEFAULT_WIDTH_ACCOUNT_ACCOUNT ); + m_pListAccounts->addColumn( i18n( "Server" ), DEFAULT_WIDTH_ACCOUNT_SERVER ); + m_pListAccounts->addColumn( i18n( "User" ), DEFAULT_WIDTH_ACCOUNT_USER ); + m_pListAccounts->addColumn( i18n( "Messages" ), DEFAULT_WIDTH_ACCOUNT_MESSAGES ); + m_pListAccounts->addColumn( i18n( "Size" ), DEFAULT_WIDTH_ACCOUNT_SIZE ); + m_pListAccounts->setAllColumnsShowFocus( true ); + connect( m_pListAccounts, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint &, int ) ), SLOT( slotAccountContext( QListViewItem*, const QPoint &, int ) ) ); + connect( m_pListAccounts, SIGNAL( clicked( QListViewItem*, const QPoint &, int) ), SLOT( slotAccountClicked( QListViewItem*, const QPoint &, int ) ) ); + + //create message list + m_pListMessages = new KListView( this, "messages" ); + m_pListMessages->setSelectionMode( QListView::Extended ); + m_pListMessages->setAllColumnsShowFocus( true ); + m_pListMessages->setSorting( ShowListViewItem::_colNumber ); // sort number column + m_pListMessages->setShowSortIndicator( true ); + m_pListMessages->addColumn( i18n( "Number" ), DEFAULT_WIDTH_MESSAGE_NUMBER ); + m_pListMessages->addColumn( i18n( "Account" ), DEFAULT_WIDTH_MESSAGE_ACCOUNT ); + m_pListMessages->addColumn( i18n( "From" ), DEFAULT_WIDTH_MESSAGE_FROM ); + m_pListMessages->addColumn( i18n( "To" ), DEFAULT_WIDTH_MESSAGE_TO ); + m_pListMessages->addColumn( i18n( "Subject" ), DEFAULT_WIDTH_MESSAGE_SUBJECT ); + m_pListMessages->addColumn( i18n( "Date" ), DEFAULT_WIDTH_MESSAGE_DATE ); + m_pListMessages->addColumn( i18n( "Size" ), DEFAULT_WIDTH_MESSAGE_SIZE ); + m_pListMessages->addColumn( i18n( "Content" ), DEFAULT_WIDTH_MESSAGE_CONTENT ); + m_pListMessages->addColumn( i18n( "State" ), DEFAULT_WIDTH_MESSAGE_STATE ); + connect( m_pListMessages, SIGNAL( rightButtonClicked( QListViewItem*, const QPoint &, int) ), SLOT( slotMessageContext( QListViewItem*, const QPoint &, int ) ) ); + connect( m_pListMessages, SIGNAL( doubleClicked( QListViewItem* ) ), SLOT( slotMessageDoubleClicked( QListViewItem* ) ) ); + connect( m_pListMessages, SIGNAL( clicked( QListViewItem* ) ), SLOT( slotMessageClicked( QListViewItem* ) ) ); + + //read the geometry from the application config file + readOptions(); + + +} + +KshowmailView::~KshowmailView() +{ + delete m_pListAccounts; + delete m_pListMessages; +} + +void KshowmailView::readOptions() +{ + //read splitter geometry + config->setGroup ("Display Options"); + QValueList size; + size.append (config->readNumEntry ("sizeaccounts", 40)); + size.append (config->readNumEntry ("sizemessages", 50)); + setSizes (size); + + // read layout of the list views + m_pListAccounts->restoreLayout( config, CONFIG_GROUP_ACCOUNT_LIST ); + m_pListMessages->restoreLayout( config, CONFIG_GROUP_MESSAGE_LIST ); +} + +void KshowmailView::saveOptions (KConfig* config) +{ +// kdDebug () << "KshowmailView::saveOptions" << endl; + config->setGroup("Display Options"); + //splitter + QValueList size = sizes (); + config->writeEntry ("sizeaccounts", size [0]); + config->writeEntry ("sizemessages", size [1]); + // layout + m_pListAccounts->saveLayout ( config, CONFIG_GROUP_ACCOUNT_LIST ); + m_pListMessages->saveLayout (config, CONFIG_GROUP_MESSAGE_LIST ); +} + + +void KshowmailView::slotMessageContext( QListViewItem* pItem, const QPoint&, int ) +{ + if( pItem != NULL ) + { + //get pointer to the main widget + KShowMailApp* theApp = ( KShowMailApp * )parentWidget(); + + //create and show popup menu + QWidget* w = theApp->factory()->container( "mail_context_popup", theApp ); + QPopupMenu* popup = static_cast( w ); + popup->exec( QCursor::pos() ); + + //select clicked item + m_pListMessages->setSelected (pItem, true); + } +} + +void KshowmailView::slotAccountContext( QListViewItem* pItem, const QPoint&, int ) +{ + if ( pItem != NULL ) + { + //get pointer to the main widget + KShowMailApp* theApp = ( KShowMailApp * )parentWidget(); + + //create and show popup menu + QWidget* w = theApp->factory()->container( "account_context_popup", theApp ); + QPopupMenu* popup = static_cast( w ); + popup->exec( QCursor::pos() ); + + //select clicked item + m_pListAccounts->setSelected( pItem, true ); + } +} + +void KshowmailView::slotAccountClicked( QListViewItem* pItem, const QPoint&, int col ) +{ + + //get application config object (kshowmailrc) + KConfig* config = KApplication::kApplication()->config(); + + if( col == 0 ) + { + KShowMailApp *theApp = (KShowMailApp *)parentWidget(); + ConfigElem* pElem = theApp->m_ConfigList.getSelectedAccount(); + + if( pElem != NULL ) + { + //get account name + QString name = pElem->getAccountName(); + + //set config group + config->setGroup( name ); + + //toggle account active state + pElem->setActive( !pElem->isActive() ); + + if( pElem->isActive() ) + { + //set active picture + pItem->setPixmap( 0, *m_pixOk ); + + //write active state into config file + config->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, true ); + config->sync(); + } + else + { + //remove active picture + pItem->setPixmap( 0, 0 ); + + //write active state into config file + config->writeEntry( CONFIG_ENTRY_ACCOUNT_ACTIVE, false ); + config->sync(); + } + + emit signalActiveChanged (); + } + } +} + +void KshowmailView::slotMessageDoubleClicked (QListViewItem* pItem) +{ + if (pItem) + { +// m_pListMessages->setSelected (pItem, true); + + KShowMailApp *theApp=(KShowMailApp *) parentWidget(); + theApp->slotShowHeader (); + } +} + +void KshowmailView::slotMessageClicked (QListViewItem* pItem) +{ + if (pItem) + { +// m_pListMessages->setSelected (pItem, true); + + KShowMailApp *theApp=(KShowMailApp *) parentWidget(); + theApp->delayNextRefresh(); + } +} + +void KshowmailView::clearMailListView( ) +{ + m_pListMessages->clear(); +} + +ShowListViewItem* KshowmailView::insertMail( QString& number, QString& account, QString& from, QString& to, QString& subject, QString& date, QString& size, QString& content, QString& state, QString& time ) +{ + //create item + ShowListViewItem* item = new ShowListViewItem( m_pListMessages ); + + //set content + item->setNumber( number ); + item->setAccount( account ); + item->setFrom( from ); + item->setTo( to ); + item->setSubject( subject ); + item->setDate( date ); + item->setSize( size ); + item->setContent( content ); + item->setState( state ); + item->setTime( time ); + + return item; +} + +void KshowmailView::refreshSetup( ) +{ + QString ConfigEntryDisplay; //entry of the config about show or hide column + QString ConfigEntrySavedWidth; //entry of the config about saved width + int DefaultWidth = 100; //default width of the proceeded column + bool DefaultDisplay = true; //default show or hide of the proceeded column + + //set columns of the account list + config->setGroup( CONFIG_GROUP_ACCOUNT_LIST ); + for( int column = 0; column <= 5; column++ ) //iterate over all columns + { + //get config entries and defaults of the proceeded column from the constants header + switch( column ) + { + case 0: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_ACTIVE; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_ACTIVE; + DefaultWidth = DEFAULT_WIDTH_ACCOUNT_ACTIVE; + DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_ACTIVE; + break; + + case 1: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_ACCOUNT; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_ACCOUNT; + DefaultWidth = DEFAULT_WIDTH_ACCOUNT_ACCOUNT; + DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_ACCOUNT; + break; + + case 2: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_SERVER; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_SERVER; + DefaultWidth = DEFAULT_WIDTH_ACCOUNT_SERVER; + DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_SERVER; + break; + + case 3: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_USER; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_USER; + DefaultWidth = DEFAULT_WIDTH_ACCOUNT_USER; + DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_USER; + break; + + case 4: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_MESSAGES; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_MESSAGES; + DefaultWidth = DEFAULT_WIDTH_ACCOUNT_MESSAGES; + DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_MESSAGES; + break; + + case 5: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_ACCOUNT_SIZE; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_ACCOUNT_SIZE; + DefaultWidth = DEFAULT_WIDTH_ACCOUNT_SIZE; + DefaultDisplay = DEFAULT_DISPLAY_ACCOUNT_SIZE; + break; + } //end select + + //get desired column state + bool showColumn = config->readBoolEntry( ConfigEntryDisplay, DefaultDisplay ); + + //get currently column state + bool curShowed = m_pListAccounts->columnWidth( column ) > 0; + + if( showColumn ) + { + //column will be shown + + if( !curShowed ) + { + //the column is currently not be shown + + //get saved width or take default width + int savedWidth = config->readNumEntry( ConfigEntrySavedWidth, DefaultWidth ); + + //set column width + m_pListAccounts->setColumnWidth( column, savedWidth ); + } + //else: the column is currently shown; do nothing + } + else + { + //column will not be shown + + if( curShowed ) + { + //the column is currently shown + + //save current width + config->writeEntry( ConfigEntrySavedWidth, m_pListAccounts->columnWidth( column ) ); + + //hide column + m_pListAccounts->hideColumn( column ); + } + //else: the column is already hidden; do nothing + } + + } //end column loop + + //set columns of the message list + config->setGroup( CONFIG_GROUP_MESSAGE_LIST ); + for( int column = 0; column <= 8; column++ ) //iterate over all columns + { + //get config entries and defaults of the proceeded column from the constants header + switch( column ) + { + case 0: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_NUMBER; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_NUMBER; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_NUMBER; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_NUMBER; + break; + + case 1: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_ACCOUNT; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_ACCOUNT; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_ACCOUNT; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_ACCOUNT; + break; + + case 2: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_FROM; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_FROM; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_FROM; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_FROM; + break; + + case 3: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_TO; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_TO; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_TO; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_TO; + break; + + case 4: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_SUBJECT; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_SUBJECT; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_SUBJECT; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_SUBJECT; + break; + + case 5: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_DATE; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_DATE; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_DATE; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_DATE; + break; + + case 6: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_SIZE; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_SIZE; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_SIZE; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_SIZE; + break; + + case 7: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_CONTENT; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_CONTENT; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_CONTENT; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_CONTENT; + break; + + case 8: ConfigEntryDisplay = CONFIG_ENTRY_DISPLAY_MESSAGE_STATE; + ConfigEntrySavedWidth = CONFIG_ENTRY_OLD_WIDTH_MESSAGE_STATE; + DefaultWidth = DEFAULT_WIDTH_MESSAGE_STATE; + DefaultDisplay = DEFAULT_DISPLAY_MESSAGE_STATE; + break; + + } //end select + + //get desired column state + bool showColumn = config->readBoolEntry( ConfigEntryDisplay, DefaultDisplay ); + + //get currently column state + bool curShowed = m_pListMessages->columnWidth( column ) > 0; + + if( showColumn ) + { + //column will be shown + + if( !curShowed ) + { + //the column is currently not be shown + + //get saved width or take default width + int savedWidth = config->readNumEntry( ConfigEntrySavedWidth, DefaultWidth ); + + //set column width + m_pListMessages->setColumnWidth( column, savedWidth ); + } + //else: the column is currently shown; do nothing + } + else + { + //column will not be shown + + if( curShowed ) + { + //the column is currently shown + + //save current width + config->writeEntry( ConfigEntrySavedWidth, m_pListMessages->columnWidth( column ) ); + + //hide column + m_pListMessages->hideColumn( column ); + } + //else: the column is already hidden; do nothing + } + + } //end column loop + + //save current layout + m_pListAccounts->saveLayout( config, CONFIG_GROUP_ACCOUNT_LIST ); + m_pListMessages->saveLayout( config, CONFIG_GROUP_MESSAGE_LIST ); + config->sync(); +} -- cgit v1.2.3