Changeset 374:159b8dc48877 in SMSSender for frontend/gui/ui/main.cpp


Ignore:
Timestamp:
Apr 14, 2014 12:53:08 PM (5 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
separation-frontend-backend
Message:
  • Code cleanup in some classes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/gui/ui/main.cpp

    r362 r374  
    5555
    5656        /* Accounts */
    57     accountModel_       = new AccountTreeModel(this, true, m_managerFactory.accountManager(), *m_managerFactory.gatewayManager());
    58     accountFilterModel_ = new LoadedAccountModel(this, *m_managerFactory.accountManager());
     57    accountModel_ = new AccountTreeModel(this, true,
     58                                         m_managerFactory.accountManager(),
     59                                         *m_managerFactory.gatewayManager());
     60    accountFilterModel_ =
     61            new LoadedAccountModel(this, *m_managerFactory.accountManager());
    5962        accountFilterModel_->setSourceModel(accountModel_);
    6063        accountFilterModel_->setSortCaseSensitivity(Qt::CaseInsensitive);
     
    6770
    6871        /* Contact / Groups */
    69     contactGroupListModel_ = new ContactGroupListModel(this, *m_managerFactory.contactManager(), *m_managerFactory.groupManager());
     72    contactGroupListModel_ = new ContactGroupListModel(
     73                this, *m_managerFactory.contactManager(),
     74                *m_managerFactory.groupManager());
    7075        contactGroupSortModel_ = new QSortFilterProxyModel(this);
    7176        contactGroupSortModel_->setSourceModel(contactGroupListModel_);
     
    9398            this, SLOT(on_lstContacts_completerActivated(const QString&)));
    9499
    95     connect(m_managerFactory.accountInitManager(), SIGNAL(accountInitStateChanged(IAccount*)),
     100    connect(m_managerFactory.accountInitManager(),
     101            SIGNAL(accountInitStateChanged(IAccount*)),
    96102            this, SLOT(onAccountInitStateChanged(IAccount*)));
    97     connect(m_managerFactory.accountInitManager(), SIGNAL(accountInitFailed(IAccount*, const EException&)),
     103    connect(m_managerFactory.accountInitManager(),
     104            SIGNAL(accountInitFailed(IAccount*, const EException&)),
    98105            this, SLOT(onAccountInitFailed(IAccount*, const EException&)));
    99106
     
    123130    if (m_managerFactory.settingsManager()->getCheckForUpdates()) {
    124131        if (m_managerFactory.updateManager()->isUpdateAvailable(UpdateManager::utEdge)) {
    125             onUpdateAvailable(m_managerFactory.updateManager()->newestVersion(UpdateManager::utEdge), UpdateManager::utEdge);
     132            onUpdateAvailable(m_managerFactory.updateManager()->newestVersion(UpdateManager::utEdge),
     133                              UpdateManager::utEdge);
    126134        } else {
    127             connect(m_managerFactory.updateManager(), SIGNAL(updateAvailable(const SVersion&, UpdateManager::UpdateType)),
    128                     this, SLOT(onUpdateAvailable(const SVersion&, UpdateManager::UpdateType)));
     135            connect(m_managerFactory.updateManager(),
     136                    SIGNAL(updateAvailable(const SVersion&, UpdateManager::UpdateType)),
     137                    this,
     138                    SLOT(onUpdateAvailable(const SVersion&, UpdateManager::UpdateType)));
    129139        }
    130140        }
     
    147157
    148158    if (m_managerFactory.accountManager()->accounts().isEmpty()) {
    149         QScopedPointer<EditAccount> ea(
    150                     new EditAccount(this, NULL, *m_managerFactory.accountManager(), *m_managerFactory.gatewayManager()));
     159        QScopedPointer<EditAccount> ea(new EditAccount(
     160                                           this, NULL,
     161                                           *m_managerFactory.accountManager(),
     162                                           *m_managerFactory.gatewayManager()));
    151163        if (ea->exec() == QDialog::Accepted){ // Wait for return
    152164            m_managerFactory.accountManager()->saveAccount(ea->account());
     
    164176
    165177IAccount* Main::selectedAccount() const {
    166     QModelIndex idx = accountFilterModel_->mapToSource(accountFilterModel_->index(ui.lstAccounts->currentIndex(), 0));
     178    QModelIndex idx = accountFilterModel_->mapToSource(
     179                accountFilterModel_->index(ui.lstAccounts->currentIndex(), 0));
    167180    return accountModel_->dataObject(idx);
    168181}
     
    211224}
    212225
    213 bool Main::isNodeContactOrHasContact(const QTreeWidgetItem* node, const SContact& contact){
     226bool Main::isNodeContactOrHasContact(const QTreeWidgetItem* node,
     227                                     const SContact& contact)
     228{
    214229    if (isContactNode(node)){
    215230        const SContact *contact_ = getContactOfNode(node);
     
    239254    return getRecipientContacts(withGroupContacts, NULL);
    240255}
    241 QSet<const SContact*> Main::getRecipientContacts(bool withGroupContacts, QTreeWidgetItem* node) {
     256QSet<const SContact*> Main::getRecipientContacts(bool withGroupContacts,
     257                                                 QTreeWidgetItem* node)
     258{
    242259    QSet<const SContact*> result;
    243260
    244261    if (node == NULL) {
    245262        for (int i = 0; i < ui.treeRecipients->topLevelItemCount(); ++i) {
    246             result.unite(getRecipientContacts(withGroupContacts, ui.treeRecipients->topLevelItem(i)));
     263            result.unite(getRecipientContacts(
     264                             withGroupContacts,
     265                             ui.treeRecipients->topLevelItem(i)));
    247266        }
    248267    }
     
    275294    }
    276295
    277     // TODO: Check if the given recipient/number is a valid recipient for the selected gateway
     296    // TODO: Check if the given recipient/number is a valid recipient for the
     297    //       selected gateway
    278298
    279299    contactGroupListModel_->addFilteredContact(contact);
     
    373393        if (task) {
    374394            connect(task, SIGNAL(exceptionOccured(STask*)),
    375                     this, SLOT(onSMSSendingErrorOccured(STask*)), Qt::DirectConnection);
     395                    this, SLOT(onSMSSendingErrorOccured(STask*)),
     396                    Qt::DirectConnection);
    376397            connect(task, SIGNAL(finished(STask*)),
    377                     this, SLOT(onSMSSendingFinished(STask*)), Qt::DirectConnection);
     398                    this, SLOT(onSMSSendingFinished(STask*)),
     399                    Qt::DirectConnection);
    378400
    379401            QScopedPointer<QDialog> sd(m_managerFactory.guiManager()->createNewSendingDialog(this, task));
     
    405427void Main::on_lstContacts_returnPressed() {
    406428    if (ui.lstContacts->currentIndex() < 0) {
    407         SNumber number(ui.lstContacts->lineEdit()->text().trimmed(), SNumber::GuessFormat);
     429        SNumber number(ui.lstContacts->lineEdit()->text().trimmed(),
     430                       SNumber::GuessFormat);
    408431        if (!number.isValid()) {
    409             // If nothing is selected in the completion, just use the topmost completion
     432            // If nothing is selected in the completion, just use the topmost
     433            // completion.
    410434            ui.lstContacts->completer()->setCurrentRow(0);
    411435            ui.lstContacts->lineEdit()->setText(ui.lstContacts->completer()->currentCompletion());
    412436        } else {
    413             // There was entered a valid number, so do not select any completion but search after the number.
     437            // There was entered a valid number, so do not select any completion
     438            // but search after the number.
    414439            on_btnAddRecipient_clicked();
    415440        }
     
    427452
    428453void Main::on_btnAddRecipient_clicked(){
     454    // Ignore multiple calls of btnAddRecipient-clicked events
    429455    if (!m_recipientAddingEnabled) return;
    430     m_recipientAddingEnabled = false; // Ignore multiple calls of btnAddRecipient-clicked events
    431 
    432     QModelIndex idx = contactGroupSortModel_->mapToSource(contactGroupSortModel_->index(ui.lstContacts->currentIndex(), 0));
     456    m_recipientAddingEnabled = false;
     457
     458    QModelIndex idx = contactGroupSortModel_->mapToSource(
     459                contactGroupSortModel_->index(ui.lstContacts->currentIndex(), 0));
    433460    if (idx.isValid()) {
    434         ContactGroupContainer recipientCntr = contactGroupListModel_->dataObject(idx);
     461        ContactGroupContainer recipientCntr =
     462                contactGroupListModel_->dataObject(idx);
    435463        if (recipientCntr.contact) {
    436464            addRecipient(*recipientCntr.contact);
     
    454482                                                              QMessageBox::Yes | QMessageBox::No,
    455483                                                              QMessageBox::Yes)) {
    456                     QScopedPointer<EditContact> ec(new EditContact(
    457                                                        this, recipient.data(), false,
    458                                                        *m_managerFactory.contactManager(), *m_managerFactory.groupManager()));
     484                    QScopedPointer<EditContact> ec(
     485                                new EditContact(this, recipient.data(), false,
     486                                                *m_managerFactory.contactManager(),
     487                                                *m_managerFactory.groupManager()));
    459488                    if (ec->exec() == QDialog::Accepted) { // Wait for return
    460489                        m_managerFactory.contactManager()->saveContact(recipient.take()); // Takes ownership
    461490                    }
     491                } else {
     492                    recipient.take(); // FIXME: Memleak when not managed by contactmanager! (add it to contactmanager w/o saving?)
    462493                }
    463                 if (recipient->name() == "") {
    464                     recipient->setName(number.toString(SNumber::IsoFormat));
     494                if (r->name() == "") {
     495                    r->setName(number.toString(SNumber::IsoFormat));
    465496                }
    466497
    467                 recipient.take(); // FIXME: Memleak when not managed by contactmanager! (add it to contactmanager w/o saving?)
    468498                addRecipient(*r);
    469499            }
     
    505535    Q_UNUSED(checked);
    506536
    507     QScopedPointer<AccountList> al(new AccountList(this, m_managerFactory.accountManager(), *m_managerFactory.gatewayManager()));
     537    QScopedPointer<AccountList> al(new AccountList(
     538                                       this, m_managerFactory.accountManager(),
     539                                       *m_managerFactory.gatewayManager()));
    508540    al->exec();
    509541}
     
    513545
    514546    QScopedPointer<AddressBook> ab(
    515                 new AddressBook(this, m_managerFactory.contactManager(), m_managerFactory.groupManager(),
    516                                 *m_managerFactory.contactImporterManager(), m_managerFactory.guiManager()));
     547                new AddressBook(this, m_managerFactory.contactManager(),
     548                                m_managerFactory.groupManager(),
     549                                *m_managerFactory.contactImporterManager(),
     550                                m_managerFactory.guiManager()));
    517551    ab->exec();
    518552}
     
    523557    QScopedPointer<SettingsDialog> s(
    524558                new SettingsDialog(this, m_managerFactory.settingsManager(),
    525                                    m_managerFactory.suffixManager(), m_managerFactory.updateManager()));
     559                                   m_managerFactory.suffixManager(),
     560                                   m_managerFactory.updateManager()));
    526561        s->exec();
    527562}
     
    638673            const EException &ex = static_cast<ErrorAccount*>(account)->error();
    639674
    640             errorMsg += QString("[%1]: %2\n").arg(account->name(), ex.unchainedWhat());
     675            errorMsg += QString("[%1]: %2\n")
     676                    .arg(account->name())
     677                    .arg(ex.unchainedWhat());
    641678            if (ex.hasChainedException()) {
    642                 detailedMsg += QString("[%1]: %2\n").arg(account->name(), ex.chainedException().chainedWhat());
     679                detailedMsg += QString("[%1]: %2\n")
     680                        .arg(account->name())
     681                        .arg(ex.chainedException().chainedWhat());
    643682            }
    644683        }
     
    647686
    648687        QMessageBox msg(QMessageBox::Warning, tr("Error occured"),
    649                         tr("Errors occured while loading your accounts."), QMessageBox::Ok, this);
     688                        tr("Errors occured while loading your accounts."),
     689                        QMessageBox::Ok, this);
    650690        msg.setDefaultButton(QMessageBox::Ok);
    651691        msg.setInformativeText(errorMsg);
     
    660700    }
    661701
    662     if ((ui.lstAccounts->currentIndex() == -1)
    663             || (ui.lstAccounts->currentIndex() >= (ui.lstAccounts->count() - 1))) {
     702    if ((ui.lstAccounts->currentIndex() == -1) ||
     703        (ui.lstAccounts->currentIndex() >= (ui.lstAccounts->count() - 1))) {
    664704        // No account selected, but one is loaded now -> autoselect one
    665705        ui.lstAccounts->setCurrentIndex(ui.lstAccounts->count() - 1);
     
    668708
    669709void Main::onSMSSendingFinished(STask* task) {
    670     metaObject()->invokeMethod(this, "smsSendingFinished", Qt::QueuedConnection, Q_ARG(STask::Result, task->taskResult()));
     710    metaObject()->invokeMethod(this, "smsSendingFinished", Qt::QueuedConnection,
     711                               Q_ARG(STask::Result, task->taskResult()));
    671712}
    672713void Main::smsSendingFinished(STask::Result taskResult) {
     
    685726
    686727void Main::onSMSSendingErrorOccured(STask* task) {
    687     metaObject()->invokeMethod(this, "smsSendingErrorOccured", Qt::QueuedConnection, Q_ARG(const EException&, task->exception()));
     728    metaObject()->invokeMethod(this, "smsSendingErrorOccured",
     729                               Qt::QueuedConnection,
     730                               Q_ARG(const EException&, task->exception()));
    688731}
    689732void Main::smsSendingErrorOccured(const EException &exception) {
     
    696739
    697740
    698 void Main::onUpdateAvailable(const SVersion& newVersion, UpdateManager::UpdateType type) {
     741void Main::onUpdateAvailable(const SVersion& newVersion,
     742                             UpdateManager::UpdateType type)
     743{
    699744    Q_UNUSED(type);
    700745
    701     UpdateDialog* d = new UpdateDialog(this, newVersion);
     746    QScopedPointer<UpdateDialog> d(new UpdateDialog(this, newVersion));
    702747    d->exec();
    703     delete d;
    704748}
    705749
Note: See TracChangeset for help on using the changeset viewer.