Logo Search packages:      
Sourcecode: mailody-kde4 version File versions  Download package

Composer::Composer ( QWidget *  parent,
const Akonadi::Collection &  mb 
) [explicit]

Contructor

Parameters:
mb the mailbox where the resulting message will be stored.
identity the identity to use

Definition at line 74 of file composer.cpp.

References addAttachment(), and Mailody::Global::identityManager().

        : KXmlGuiWindow( parent ),
        m_lastState( To ), m_mailbox( mb ),  m_close( false ), m_dirty( false )
{
    setObjectName( "composer#" );
    setCaption( i18n( "Composer" ) );

    if ( !m_mailbox.isValid() )
        kDebug() << "Message can not be stored in " << m_mailbox.remoteId() << endl;

    connect( parent, SIGNAL( setupFinished() ), SLOT( slotStatusChanged() ) );

    m_addressbook = new QTreeWidget( this );
    m_addressbook->setColumnCount( 2 );
    QStringList headers;
    headers << i18n( "Name" ) << i18n( "Email" );
    m_addressbook->setHeaderLabels( headers );
    m_addressbook->setContextMenuPolicy( Qt::CustomContextMenu );
    connect( m_addressbook,
             SIGNAL( itemDoubleClicked( QTreeWidgetItem*,int ) ),
             SLOT( slotAddAddressFromAddressBook( QTreeWidgetItem* ) ) );
    connect( m_addressbook,
             SIGNAL( customContextMenuRequested( const QPoint & ) ),
             SLOT( slotContextMenuAddressBook() ) );

    KDirModel* dirModel = new KDirModel( this );
    m_filebrowser = new QTreeView( this );
    m_filebrowser->setEditTriggers( QAbstractItemView::NoEditTriggers );
    m_filebrowser->setModel( dirModel );
    m_filebrowser->resizeColumnToContents( KDirModel::ModifiedTime );
    m_filebrowser->hideColumn( KDirModel::Owner );
    m_filebrowser->hideColumn( KDirModel::Group );
    m_filebrowser->hideColumn( KDirModel::Type );
    m_filebrowser->hideColumn( KDirModel::Permissions );

    dirModel->dirLister()->openUrl( KUrl( "~" ) );
    connect( m_filebrowser,
             SIGNAL( doubleClicked( const QModelIndex& ) ),
             SLOT( slotAddFile( const QModelIndex& ) ) );

    m_recentbook = new MailodyBaseListView( this );
    m_recentbook->setColumnCount( 4 );
    m_recentbook->setContextMenuPolicy( Qt::CustomContextMenu );
    headers.clear();
    headers << i18n( "Email" ) << i18n( "Name" ) << i18n( "Amount" ) << i18n( "Last" );
    m_recentbook->setHeaderLabels( headers );
    m_recentbook->sortItems( 3, Qt::DescendingOrder );
    connect( m_recentbook,
             SIGNAL( itemDoubleClicked( QTreeWidgetItem*,int ) ),
             SLOT( slotAddAddressFromRecentBook( QTreeWidgetItem* ) ) );
    connect( m_recentbook,
             SIGNAL( customContextMenuRequested( const QPoint & ) ),
             SLOT( slotContextMenuRecentBook() ) );
    connect( m_recentbook,
             SIGNAL( itemEntered( QTreeWidgetItem*, int ) ),
             SLOT( slotShowRecentDetails( QTreeWidgetItem* ) ) );
    connect( m_recentbook, SIGNAL( leftWidget() ), SLOT( slotHideRecentDetails() ) );
    connect( m_recentbook, SIGNAL( viewportEntered() ), SLOT( slotHideRecentDetails() ) );


    // Dockwidgets.
    QDockWidget* addressDock = new QDockWidget( i18n( "Add&ressbook" ), this );
    addressDock->setWidget( m_addressbook );
    addressDock->setObjectName( "addressDock" );
    addressDock->setFeatures( QDockWidget::DockWidgetMovable |
                              QDockWidget::DockWidgetClosable );
    addDockWidget( Qt::LeftDockWidgetArea, addressDock );

    QDockWidget* recentDock = new QDockWidget( i18n( "Re&cent" ), this );
    recentDock->setWidget( m_recentbook );
    recentDock->setObjectName( "recentDock" );
    recentDock->setFeatures( QDockWidget::DockWidgetMovable |
                             QDockWidget::DockWidgetClosable );
    addDockWidget( Qt::LeftDockWidgetArea, recentDock );

    QDockWidget* attachDock = new QDockWidget( i18n( "At&tach File" ), this );
    attachDock->setWidget( m_filebrowser );
    attachDock->setObjectName( "attachDock" );
    attachDock->setFeatures( QDockWidget::DockWidgetMovable |
                             QDockWidget::DockWidgetClosable );
    addDockWidget( Qt::RightDockWidgetArea, attachDock );

    // check that we have state-settings saved. If not hide docks by default.
    KConfigGroup dcfg = KGlobal::config()->group( "Composer" );
    if ( !dcfg.hasKey( "FirstRun" ) ) {
        addressDock->setHidden( true );
        recentDock->setHidden( true );
        attachDock->setHidden( true );
        dcfg.writeEntry( "FirstRun",false );
    }

    tabifyDockWidget( recentDock, addressDock );

    // -------------- main layout ----//

    m_vsplitter = new QSplitter( this );
    m_vsplitter->setOrientation( Qt::Vertical );

    QWidget* widg = new QWidget( m_vsplitter );
    QGridLayout* grid = new QGridLayout( widg );
    grid->setSpacing( 6 );
    grid->setMargin( 6 );

    m_identitylabel = new QLabel( i18n( "Identity:" )+' ', widg );
    m_identityBox = new KPIMIdentities::IdentityCombo( Global::identityManager(),
            widg );
    m_identitylabel->setBuddy( m_identityBox );
    connect( m_identityBox,SIGNAL( identityChanged( uint ) ),
             SLOT( slotReplaceSignature( uint ) ) );

    m_transportlabel = new QLabel( i18n( "Transport:" )+' ', widg );
    m_transportBox = new MailTransport::TransportComboBox( widg );
    m_transportlabel->setBuddy( m_identityBox );
    connect( m_transportBox, SIGNAL( currentIndexChanged( int ) ),
             SLOT( slotTransportChanged() ) );

    QLabel* tolabel = new QLabel( i18n( "Recipient:" )+' ', widg );
    m_edit = new AddressLineEdit( widg );
    tolabel->setBuddy( m_edit );
    connect( m_edit,SIGNAL( shiftAddress() ), SLOT( slotShiftAddress() ) );
    connect( m_edit,SIGNAL( addAddress( const QString& ) ),
             SLOT( slotAddAddress( const QString& ) ) );
    connect( m_edit,SIGNAL( addAddress( const QString& ) ),
             SLOT( slotSetDirty() ) );
    connect( m_edit,SIGNAL( containsValidAddress( bool ) ),
             SLOT( slotContainsValidAddress( bool ) ) );

    m_add = new QPushButton( i18n( "Add" ), widg );
    slotContainsValidAddress( false );
    connect( m_add, SIGNAL( clicked() ), SLOT( slotAddClicked() ) );
    connect( m_add, SIGNAL( clicked() ), SLOT( slotSetDirty() ) );

    m_addressbox = new DataListView( widg,0,5 );
    m_addressbox ->setContextMenuPolicy( Qt::CustomContextMenu );
    m_addressbox->setColumnCount( 5 );
    // since we don't want the pixmaps to be editable, we deal with it
    // ourselfes
    m_addressbox->setEditTriggers( QAbstractItemView::NoEditTriggers );
    m_addressbox->setSelectionMode( QAbstractItemView::SingleSelection );
    m_addressbox->setSelectionBehavior( QAbstractItemView::SelectRows );

    headers.clear();
    headers << i18n( "Address" ) << i18n( "To" ) << i18n( "Cc" ) << i18n( "Bcc" )
    << i18n( "Del" );
    m_addressbox->setHeaderLabels( headers );
    connect( m_addressbox, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ),
             SLOT( slotEditAddress( QTreeWidgetItem*, int ) ) );
    connect( m_addressbox, SIGNAL( itemSelectionChanged() ), SLOT( slotUpdateLineEdit() ) );
    connect( m_addressbox,
             SIGNAL( customContextMenuRequested( const QPoint & ) ),
             SLOT( slotContextMenuAddressList() ) );

    m_alabel = new QLabel( i18n( "Attached:" )+' ', widg );
    m_attachview = new AttachmentWidget( widg );
    connect( m_attachview, SIGNAL( noAttachmentsLeft() ),
             SLOT( slotHideAttachmentWidget() ) );

    m_attachview->hide();
    m_alabel->setBuddy( m_attachview );
    m_alabel->hide();

    grid->addWidget( m_identitylabel,0,0, Qt::AlignRight );
    grid->addWidget( m_identityBox,0,1,1,2 );
    grid->addWidget( m_transportlabel,1,0, Qt::AlignRight );
    grid->addWidget( m_transportBox,1,1,1,2 );
    grid->addWidget( tolabel,2,0, Qt::AlignRight );
    grid->addWidget( m_edit,2,1 );
    grid->addWidget( m_add,2,2 );
    grid->addWidget( m_addressbox,3,1,1,2 );
    grid->addWidget( m_alabel,4,0, Qt::AlignRight );
    grid->addWidget( m_attachview,4,1,1,2 );
    grid->setColumnStretch( 1,10 );

    //--------------------------------------------------------

    QWidget* widg2 = new QWidget( m_vsplitter );
    QGridLayout* grid2 = new QGridLayout( widg2 );
    grid2->setSpacing( 5 );
    grid2->setMargin( 5 );

    QLabel* label = new QLabel( i18n( "Subject:" )+' ', widg );
    m_subject = new KLineEdit( widg );
    m_subject->setObjectName( "subject" );
    label->setBuddy( m_subject );
    connect( m_subject, SIGNAL( textChanged( const QString & ) ),
             SLOT( slotSetDirty() ) );

    m_text = new ComposerTextEdit( widg2 );
    m_text->setRichTextSupport( ComposerTextEdit::FullSupport );
    m_text->createActions( actionCollection() );
    connect( m_text, SIGNAL( textChanged() ), SLOT( slotSetDirty() ) );
    connect( m_text, SIGNAL( addAttachment( const KUrl& ) ),
             SLOT( slotAddFile( const KUrl& ) ) );
    KStandardAction::preferences( this,
                                  SLOT( slotSetup() ), actionCollection() );

    m_textToolBar = new KToolBar( "htmlToolBar", this, Qt::TopToolBarArea );
    m_textToolBar->setToolButtonStyle( Qt::ToolButtonIconOnly );

    m_htmlmode = new KToggleAction( this );
    m_htmlmode->setText( i18n( "HTML Mode" ) );
    actionCollection()->addAction( "toggle_html_mode", m_htmlmode );
    connect( m_htmlmode, SIGNAL( toggled( bool ) ), SLOT( slotHTMLMode( bool ) ) );

    uint identityInt = m_identityBox->currentIdentity();
    const KPIMIdentities::Identity& ident =
        Global::identityManager()->identityForUoidOrDefault( identityInt );
    bool htmlActive = ident.property( s_preferhtml ).toInt() == 1 ? false : true;
    m_htmlmode->setChecked( htmlActive );
    slotHTMLMode( htmlActive );

    m_sendmail = new KAction( this );
    m_sendmail->setText( i18n( "Send Email" ) );
    m_sendmail->setIcon( KIcon( "mail-send" ) );
    m_sendmail->setShortcut( Qt::ControlModifier + Qt::Key_Return );
    m_sendmail->setIcon( KIcon( "mail-send" ) );
    actionCollection()->addAction( "send_message", m_sendmail );
    connect( m_sendmail, SIGNAL( triggered( bool ) ), SLOT( slotSend() ) );

    m_savemail = new KAction( this );
    m_savemail->setText( i18n( "Save Email" ) );
    m_savemail->setIcon( KIcon( "document-save" ) );
    m_savemail->setEnabled( m_mailbox.isValid() );
    m_savemail->setShortcut( Qt::ControlModifier + Qt::Key_S );
    actionCollection()->addAction( "composer_save_message", m_savemail );
    connect( m_savemail, SIGNAL( triggered( bool ) ), SLOT( slotSave() ) );

    m_expandSig = new KAction( this );
    m_expandSig->setText( i18n( "Expand Signature" ) );
    actionCollection()->addAction( "expand_sig", m_expandSig );
    connect( m_expandSig, SIGNAL( triggered( bool ) ), SLOT( slotExpandSignature() ) );

    m_showIdentities = new KToggleAction( this );
    m_showIdentities->setText( i18n( "Show Identities" ) );
    actionCollection()->addAction( "options_show_identities", m_showIdentities );
    connect( m_showIdentities, SIGNAL( triggered( bool ) ),
             SLOT( slotShowIdentities( bool ) ) );

    m_showTransports = new KToggleAction( this );
    m_showTransports->setText( i18n( "Show Transports" ) );
    actionCollection()->addAction( "options_show_transports", m_showTransports );
    connect( m_showTransports, SIGNAL( triggered( bool ) ),
             SLOT( slotShowTransports( bool ) ) );

    // online / offline
    slotStatusChanged();
    connect( Solid::Networking::notifier(),
             SIGNAL( statusChanged( Solid::Networking::Status ) ),
             SLOT( slotStatusChanged() ) );


    KAction *close = new KAction( this );
    close->setText( i18n( "Close" ) );
    close->setIcon( KIcon( "window-close" ) );
    close->setShortcut( KStandardShortcut::close() );
    actionCollection()->addAction( "composer_close", close );
    connect( close, SIGNAL( triggered( bool ) ), SLOT( slotDone() ) );

    KToggleAction *toggleFixed = new KToggleAction( this );
    toggleFixed->setText( i18n( "Fixed Font" ) );
    actionCollection()->addAction( "toggle_fixed_font", toggleFixed );
    connect( toggleFixed, SIGNAL( triggered( bool ) ), SLOT( slotFixedFont( bool ) ) );

    actionCollection()->addAction( "toggle_address_dock",
                                   addressDock->toggleViewAction() );
    actionCollection()->addAction( "toggle_recent_dock",
                                   recentDock->toggleViewAction() );
    actionCollection()->addAction( "toggle_attach_dock",
                                   attachDock->toggleViewAction() );

    KStatusBarOfflineIndicator* nsi =
        new KStatusBarOfflineIndicator( this );

    QToolButton *send = new QToolButton( widg2 );
    send->setDefaultAction( m_sendmail );

    QToolButton *save = new QToolButton( widg2 );
    save->setDefaultAction( m_savemail );

    grid2->addWidget( label,0,0, Qt::AlignRight );
    grid2->addWidget( m_subject,0,1,1,4 );
    grid2->addWidget( m_textToolBar,1,0,1,5 );
    grid2->addWidget( m_text,2,0,1,5 );
    grid2->addWidget( send,3,4 );
    grid2->addWidget( save,3,3 );
    grid2->addWidget( nsi,3,2 );
    grid2->setColumnStretch( 2,10 );

    //--------------------------------------------------------

    m_vsplitter->show();
    setCentralWidget( m_vsplitter );
    setMinimumSize( QSize( 400,300 ) );
    setStandardToolBarMenuEnabled( true );
    toolBar();
    statusBar();
    setupGUI( Keys | StatusBar | ToolBar | Create | Save, "composerui.rc" );

    // set the column width of the subject to the same value
    // as the labels above the splitter. Not sure why 3*spacing is needed.
    m_identitylabel->adjustSize();
    int width = m_identitylabel->width() + ( 3*grid2->spacing() );
    grid2->setColumnMinimumWidth( 0, width );

    // read config for the splitter size
    setAutoSaveSettings( "Composer", true );
    KConfigGroup config = KGlobal::config()->group( "ComposerSplitterSize" );
    slotShowIdentities( config.readEntry( "showIdentities", false ) );
    slotShowTransports( config.readEntry( "showTransports", false ) );

    QList<int> defaultsize = config.readEntry( "vsplitter",QList<int>() );
    if ( !defaultsize.count() ) {
        defaultsize.append( 200 );
        defaultsize.append( 400 );
    }
    m_vsplitter->setSizes( defaultsize );
    m_addressbox->setSortingEnabled( false );
    m_edit->setFocus();

    // When we have time, load the addressess from ab
    QTimer::singleShot( 0, this, SLOT( slotLoadAddressBook() ) );
    QTimer::singleShot( 0, this, SLOT( slotLoadRecentBook() ) );
    m_tip = new ToolTip( this );
    m_timer = new QTimer( this );
    connect( m_timer, SIGNAL( timeout() ), SLOT( slotShowRecentDetailsDoIt() ) );

    // Statusbar stuff
    statusBar()->insertItem( QString(), 1, 10 );
    statusBar()->insertItem( m_identityBox->currentIdentityName(), 2, 1 );
    statusBar()->insertItem( QString(), 3, 1 );
    slotTransportChanged();

    connect( statusBar(), SIGNAL( pressed( int ) ),
             SLOT( slotStatusBarClicked( int ) ) );
}


Generated by  Doxygen 1.6.0   Back to index