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

Mailody::MainWindow::MainWindow (  ) 

Contructor

Definition at line 73 of file mainwindow.cpp.

References Mailody::ImapManager::startConnection().

  : KMainWindow(0), m_idlePossible(false)
{
    // First do a check for settings. If not go to the settings dialog...
    KConfig* config = kapp->config();
    config->setGroup("General");
    if (config->readEntry("imapServer").isEmpty())
        startupSetup(); // do not refresh mb list now...

    // Convert old smtp settings to an identity
    config->setGroup("General");
    if (config->hasKey("smtpServer"))
        Global::convertOldSmtpToIdentities();

    QString hp = config->readEntry("homePage", "http://www.mailody.net");

    m_db = DB::dbinstance();
    m_imapmanager = new ImapManager(this,"imapanddb");
    m_imapmanager->startConnection();

    connect(m_imapmanager, SIGNAL(showSettings()), SLOT(slotSetup()));
    connect(m_imapmanager, SIGNAL(loginOk()), SLOT(slotCheckMail()));
    connect(m_imapmanager, SIGNAL(loginOk()), SLOT(slotStartCheckMailTimer()));
    connect(m_imapmanager, SIGNAL(loginOk()), SLOT(slotFillMailBoxList()));

    connect(m_imapmanager, SIGNAL(mailBoxList(const QStringList&)),
            SLOT(slotPopulateMailBoxList(const QStringList&)));
    connect(m_imapmanager, SIGNAL(mailBoxAdded(const QString&)),
            SLOT(slotAddMailBox(const QString&)));
    connect(m_imapmanager, SIGNAL(mailBoxDeleted(const QString&)),
            SLOT(slotDelMailBox(const QString&)));

    connect(m_imapmanager,
            SIGNAL(mailBox( const QString&, const QStringList& )),
            SLOT(slotPopulateHeaderList(const QString&, const QStringList& )));
    connect(m_imapmanager,
            SIGNAL(mailBoxAddition(const QString&, const QStringList&)),
            SLOT(slotAddHeaderList(const QString&, const QStringList&)));
    connect(m_imapmanager, SIGNAL(messageCount(const QString&, int)),
            SLOT(slotUpdateMessageCount(const QString&, int)));
    connect(m_imapmanager, SIGNAL(unseenCount(const QString&, int)),
            SLOT(slotUpdateUnseenMessageCount(const QString&, int)));

            // TODO:
    connect(m_imapmanager, SIGNAL(allUidsKnown(const QString&)),
            SLOT(slotAllMessages(const QString&)));
    connect(m_imapmanager, SIGNAL(status(const QString&)),
            SLOT(slotUpdateStatusBar(const QString&)));
    connect(m_imapmanager, SIGNAL(statusError(const QString&)),
            SLOT(slotUpdateStatusBarRestoreMouse(const QString&)));
    connect(m_imapmanager, SIGNAL(statusReady()),
            SLOT(slotClearStatusBar()));

    m_first = new QSplitter(this);

    m_mailboxList = new MailBoxListView(m_first);
    connect(m_mailboxList,
            SIGNAL(selectionChanged( QListViewItem* )),
            SLOT( slotSelectMailBox()));
    connect(m_mailboxList,
            SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint &)),
            SLOT(slotContextMenuMailbox(KListView*, QListViewItem*,
                 const QPoint &)));
    connect(m_mailboxList,
            SIGNAL(dropped(QDropEvent*, QListViewItem *)),
            SLOT(slotDropped(QDropEvent*)));

    m_nextUnreadAction = new KAction(   i18n("Next unread"), "next",
                                    Qt::Key_Space, this, SLOT(slotNextUnread()),
                                    actionCollection(),"next_unread");
    m_syncAction = new KAction(   i18n("Sync mailbox with server"), 0,
                                    this, SLOT(slotSyncMailBox()),
                                    actionCollection(),"sync_mailbox");
    m_expungeAction = new KAction(  i18n("Remove the deleted messages"),
                                     "remove", 0, this,
                                     SLOT(slotExpungeMailBox()),
                                     actionCollection(),"expunge_mailbox");
    m_selectAllAction = new KAction(i18n("Select all messages"), "select_all",
                                    KStdAccel::selectAll(), this,
                                    SLOT(slotSelectAllMessages()),
                                    actionCollection(),"select_all_msg");
    m_childSortAction = new KToggleAction(i18n("Sort on youngest child"),
                              0, 0, this,
                              SLOT(slotSortOnYoungestChild()),
                              actionCollection(), "sort_youngest_child");
    m_hideDeletedAction = new KToggleAction(i18n("Hide deleted messages"),
                              0, 0, this,
                              SLOT(slotHideDeleted()),
                              actionCollection(), "hide_deleted");

    m_second = new QSplitter(m_first);
    m_second->setOrientation(Qt::Vertical);

    QWidget* widg = new QWidget(m_second);
    QGridLayout* gbox = new QGridLayout(widg,0,0);

    m_headerList = new HeaderListView(widg);
    connect(m_headerList, SIGNAL(scrollDown()),
            SLOT( slotTabScrollDown()));
    connect(m_headerList, SIGNAL(scrollUp()),
            SLOT( slotTabScrollUp()));
    connect(m_headerList, SIGNAL(scrollPageDown()),
            SLOT( slotTabScrollPageDown()));
    connect(m_headerList, SIGNAL(scrollPageUp()),
            SLOT( slotTabScrollPageUp()));
    connect(m_headerList, SIGNAL(selectionChanged()),
            SLOT( slotShowMessage()));
    connect(m_headerList, SIGNAL(mouseButtonPressed( int, QListViewItem *,
                                  const QPoint&, int )),
            SLOT( slotMouseClickInHeaders( int, QListViewItem*, const QPoint& )));

    //------------------ Search line -----------------------------//
    // The searchlinewidget is not used as we can not relyablie
    // connect to a textChanged signal because creation is delayed

    KToolBar* searchBar = new KToolBar( widg, "searchbar");
    searchBar->setMovingEnabled( false );
    searchBar->boxLayout()->setSpacing( KDialog::spacingHint() );

    QToolButton* clearButton = new QToolButton(searchBar);
    QIconSet icon = SmallIconSet(
            QApplication::reverseLayout() ? "clear_left" : "locationbar_erase");
    clearButton->setIconSet(icon);
    clearButton->show();

    QLabel *label = new QLabel(i18n("S&earch:"), searchBar, "kde toolbar widget");

    m_searchLine = new KListViewSearchLine( searchBar, m_headerList );
    label->setBuddy(m_searchLine);

    connect(clearButton, SIGNAL(clicked()), this,
            SLOT(slotSearchLineClear()));
    connect(m_searchLine, SIGNAL(textChanged(const QString&)),
            SLOT(slotSearchLineChange(const QString&)));

    searchBar->setStretchableWidget( m_searchLine );

    gbox->addWidget(searchBar,0,0);
    gbox->addWidget(m_headerList,1,0);

    m_right = new QHBox( m_second );

    // ---------------- Tab Widget -------------------//

    m_tabWidget = new KTabWidget( m_right );
    m_tabWidget->setTabPosition( QTabWidget::Top );
    m_tabWidget->setTabReorderingEnabled( true );
    m_tabWidget->setAutomaticResizeTabs( true );
    m_tabWidget->setTabCloseActivatePrevious( true );

    QToolButton* button = new QToolButton( m_tabWidget );
    button->setIconSet( SmallIcon( "tab_new" ) );
    button->adjustSize();
    m_tabWidget->setCornerWidget( button, TopLeft );

    m_closeButton = new QToolButton(m_tabWidget);
    m_closeButton->setIconSet( SmallIcon("tab_remove") );
    m_closeButton->adjustSize();
    m_closeButton->setEnabled(false);
    m_tabWidget->setCornerWidget( m_closeButton, TopRight );

    connect(button, SIGNAL(clicked()), SLOT(slotNewTab()));
    connect(m_closeButton, SIGNAL(clicked()), SLOT(slotDeleteTab()));
    connect(m_tabWidget, SIGNAL(closeRequest(QWidget*)),
            SLOT(slotDeleteTab(QWidget*)));
    connect(m_tabWidget, SIGNAL(contextMenu(QWidget*, const QPoint &)),
            SLOT(slotContextMenuTab(QWidget*, const QPoint &)));
    connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)),
            SLOT(slotCurrentTabChanged(QWidget*)));
    // add a ctrl-w....
    m_closeAction = new KAction( i18n("Close tab"), Qt::CTRL + Qt::Key_W,
                                  this, SLOT(slotDeleteTab()),
                                  actionCollection(),"close_tab");
    kapp->config()->setGroup("General");
    if (kapp->config()->readBoolEntry("AutoHideTabBar"))
        m_tabWidget->setTabBarHidden(true);

    // Dont load the favorite website yet, first setup all the actions.
    m_tabWidget->show();

    // ------------------ Load settings ----------------------//

    kapp->config()->setGroup("MainWindowSplitterSize");
    QValueList<int> defaultsize1 = config->readIntListEntry("vsplitter");
    if (!defaultsize1.count())
    {
        defaultsize1.append(170);
        defaultsize1.append(460);
    }

    QValueList<int> defaultsize2 = config->readIntListEntry("hsplitter");
    if (!defaultsize2.count())
    {
        defaultsize2.append(280);
        defaultsize2.append(691);
    }

    m_first->setSizes(defaultsize1);
    m_second->setSizes(defaultsize2);

    m_headerList->restoreLayout(config,"MainWindowHeaderListSize");
    m_mailboxList->restoreLayout(config,"MainWindowMailboxListSize");

    // -------------------- Create actions --------------------//

    KStdAction::quit(this, SLOT(slotQuit()), actionCollection(),
                     "app_exit");
    m_msgSaveAction = KStdAction::saveAs(this, SLOT(slotSave()),
                                       actionCollection(), "msg_save");
    m_msgPrintAction = KStdAction::print(this, SLOT(slotPrint()),
                                       actionCollection(), "msg_print");
    m_msgZoomInAction = KStdAction::zoomIn(this, SLOT(slotZoomIn()),
                                           actionCollection(), "msg_zoom_in");
    m_msgZoomOutAction  = KStdAction::zoomOut(this, SLOT(slotZoomOut()),
                                              actionCollection(),
                                              "msg_zoom_out");
    KStdAction::preferences(this, SLOT(slotSetup()), actionCollection());
    KStdAction::configureNotifications(this, SLOT(slotNotifications()),
                                       actionCollection());

    new KAction(i18n("Sync mailbox list"), 0, this,
                SLOT(slotSyncMailBoxList()),
                actionCollection(), "sync_mblist");
    new KAction(i18n("Check for Mail Now"), "mail_get",
                Qt::CTRL + Qt::Key_L , this,
                SLOT(slotCheckMail()),
                actionCollection(), "check_mail");

    m_plainTextAction = new KToggleAction( i18n( "Show as Text" ), "text",
                                          Qt::Key_F10, this,
                                          SLOT(slotToggleHTML()),
                                          actionCollection(), "toggle_html" );
    m_sourceAction = new KToggleAction( i18n( "Show source" ), "text_block",
                                         Qt::Key_V, this,
                                         SLOT(slotToggleSource()),
                                         actionCollection(), "toggle_source" );
    m_fixedfontAction = new KToggleAction( i18n( "Use fixed font" ),
                                         Qt::Key_X, this,
                                         SLOT(slotToggleFixedFont()),
                                         actionCollection(), "toggle_fixedfont" );
    m_externalImageAction = new KToggleAction( i18n( "Load external images" ),
                                         0, this,
                                         SLOT(slotToggleExternalImage()),
                                         actionCollection(),
                                         "toggle_externalimage" );
    m_msgDelAction = new KToggleAction( i18n("Message deleted"),
                                   "mail_delete", Qt::Key_Delete, this,
                                   SLOT(slotToggleDelete()),
                                   actionCollection(),"delete_message");
    /*m_relatedAction = new KToggleAction( i18n("What's related"),
                                   0, Qt::Key_W, this,
                                   SLOT(slotIsolateItem()),
                                   actionCollection(),"related_message");*/
    m_msgNewAction = KStdAction::openNew( this, SLOT( slotNewMessage() ),
                         actionCollection(), "compose_new_message" );
    m_msgNewAction->setIcon("mail_new3");
    m_msgNewAction->setEnabled( true );

    m_msgNewActionMenu = new KActionMenu( i18n( "New message to" ),
                                    "compose_new_message",
                                    actionCollection(),
                                    "compose_new_messageMenu" );
    m_msgNewActionMenu->setIcon("mail_new3");
    m_msgNewActionMenu->setEnabled( true );

    connect(m_msgNewActionMenu, SIGNAL(activated()),
            SLOT(slotNewMessage()));
    connect(m_msgNewActionMenu->popupMenu(), SIGNAL(aboutToShow()),
            SLOT(slotNewMessageMenu()));
    connect(m_msgNewActionMenu->popupMenu(), SIGNAL(activated(int)),
            SLOT(slotNewMessageMenuSelected(int)));

    m_msgReplyAction = new KAction( i18n( "Reply to message" ), "mail_replyall",
                                   Qt::CTRL + Qt::Key_R, this,
                                   SLOT(slotReplyMessage()),
                                   actionCollection(), "reply_message" );

    m_msgReEditAction = new KAction( i18n( "Re-Edit Message" ), "edit",
                                    Qt::CTRL + Qt::Key_T, this,
                                    SLOT(slotReEditMessage()),
                                    actionCollection(), "reedit_message" );

    m_msgForwardAction = new KAction( i18n( "Forward this message" ),
                                      "mail_forward",
                                   Qt::CTRL + Qt::Key_F, this,
                                   SLOT(slotForwardMessage()),
                                   actionCollection(), "forward_message" );
    m_msgForwardActionMenu = new KActionMenu( i18n( "Forward this message to" ),
                                   "mail_forward",
                                   actionCollection(), "forward_messageMenu" );
    connect(m_msgForwardActionMenu, SIGNAL(activated()),
            SLOT(slotForwardMessage()));
    connect(m_msgForwardActionMenu->popupMenu(), SIGNAL(aboutToShow()),
            SLOT(slotForwardMessageMenu()));
    connect(m_msgForwardActionMenu->popupMenu(), SIGNAL(activated(int)),
            SLOT(slotForwardMessageMenuSelected(int)));

    m_msgUser0Action = new KAction( i18n("No Label"),
                                     Qt::Key_0, this,
                                     SLOT(slotUser0()),
                                     actionCollection(),"tag_0");
    m_msgUser1Action = new KAction( i18n("Label &1"),"label1",
                                     Qt::Key_1, this,
                                     SLOT(slotUser1()),
                                     actionCollection(),"tag_1");
    m_msgUser2Action = new KAction( i18n("Label &2"),"label2",
                                     Qt::Key_2, this,
                                     SLOT(slotUser2()),
                                     actionCollection(),"tag_2");
    m_msgUser3Action = new KAction( i18n("Label &3"),"label3",
                                     Qt::Key_3, this,
                                     SLOT(slotUser3()),
                                     actionCollection(),"tag_3");
    m_msgUser4Action = new KAction( i18n("Label &4"),"label4",
                                     Qt::Key_4, this,
                                     SLOT(slotUser4()),
                                     actionCollection(),"tag_4");
    m_msgUser5Action = new KAction( i18n("Label &5"),"label5",
                                     Qt::Key_5, this,
                                     SLOT(slotUser5()),
                                     actionCollection(),"tag_5");

    // -------- set the actions according to the settings ----------//

    //this also calls setActionStates();
    slotOpenURLInNewTab( hp );

    kapp->config()->setGroup("ToggleStates");
    m_plainTextAction->setChecked(
            kapp->config()->readBoolEntry("plaintext", true));
    m_sourceAction->setChecked(
            kapp->config()->readBoolEntry("source", false));
    m_fixedfontAction->setChecked(
            kapp->config()->readBoolEntry("fixed", false));
    m_externalImageAction->setChecked(
            kapp->config()->readBoolEntry("externalimage", false));

    m_childSortAction->setChecked(
            kapp->config()->readBoolEntry("sort_youngest", false));
    m_hideDeletedAction->setChecked(
            kapp->config()->readBoolEntry("hide_deleted", false));
    slotHideDeleted();
    slotToggleHTML();

    m_first->show();
    setCentralWidget(m_first);
    setupGUI(Keys | StatusBar | ToolBar | Create | Save);
    setMinimumSize(QSize(900,750));
    setAutoSaveSettings("MainWindow", true);

    // -------------- statusbar ------------------------------------//

    m_statusText = new KSqueezedTextLabel(this);
    m_statusText->setFrameStyle( QFrame::NoFrame );
    m_statusText->setMargin(1);
    m_statusText->setText(i18n("Ready"));
    statusBar()->addWidget(m_statusText,10);
    statusBar()->setItemAlignment(1,Qt::AlignLeft);
    statusBar()->insertItem(i18n("Plain"),2,1);
    statusBar()->insertItem(i18n("Short for no ext. images",
                             "No ext."), 3, 1);
    connect(statusBar(), SIGNAL(pressed(int)),
        SLOT(slotStatusBarClicked(int)));

    m_statusTimer = new QTimer(this);
    connect(m_statusTimer, SIGNAL(timeout()), SLOT(slotStatusBarReady()));

    // -----------------prep Tooltip and checkmail timer ------------//

    m_tooltip = new ToolTip(this,"notification");
    connect(m_tooltip, SIGNAL(leftClicked(const QString&)),
            SLOT(slotSelectMB(const QString&)));

    // This is the mailcheck timer.
    m_checkMailTimer = new QTimer(this);
    connect(m_checkMailTimer, SIGNAL(timeout()), SLOT(slotCheckMail()));

    // Commandline stuff - for now only catch mailto: thingies, so I can
    // use mailody as default mua. It also assumes an INBOX.
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    if (args)
    {
        for(int i=0; i < args->count(); i++)
        {
            QString argument = args->arg(i);
            if (argument.startsWith("mailto:"))
                slotOpenComposer(argument);
        }
    }

    DCOPIface* dcopIface = new DCOPIface(this, "actions");
    connect( dcopIface, SIGNAL( signalMailTo( const QString& ) ),
             SLOT( slotOpenComposer( const QString& ) ) );
    connect( dcopIface, SIGNAL( signalCompose( const QString&, const QString& ) ),
             SLOT( slotOpenComposer( const QString&, const QString& ) ) );
}


Generated by  Doxygen 1.6.0   Back to index