source: SMSSender/src/ui/vcmain/vcmain.cpp @ 277:6050201cc5f7

Last change on this file since 277:6050201cc5f7 was 277:6050201cc5f7, checked in by Sämy Zehnder <saemy.zehnder@…>, 7 years ago
  • Fixed non-working autoselect of accounts if none is selected and one can be selected now.
File size: 22.3 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2012, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "vcmain.h"
19
20#include <QCompleter>
21#include <QDebug>
22#include <QMessageBox>
23#include <QSortFilterProxyModel>
24
25#include <algorithm>
26
27#include <snumber.h>
28#include <iaccount_tasks.h>
29
30#include "business/bcaccountmanager.h"
31#include "business/bccontactmanager.h"
32#include "business/bcgatewaymanager.h"
33#include "business/bcgroupmanager.h"
34#include "business/bcguimanager.h"
35#include "business/bcsuffixmanager.h"
36#include "business/bcupdatemanager.h"
37
38#include "ui/vcabout/vcabout.h"
39#include "ui/vcaccountlist/vcaccountlist.h"
40#include "ui/vcaddressbook/vcaddressbook.h"
41#include "ui/vceditaccount/vceditaccount.h"
42#include "ui/vceditcontact/vceditcontact.h"
43#include "ui/vcsettings/vcsettings.h"
44#include "ui/vcsendingdialog/vcsendingdialog.h"
45#include "ui/vcupdatedialog/vcupdatedialog.h"
46
47#include "ui/completers/bettercompleter.h"
48#include "ui/components/taskstatusbar.h"
49#include "ui/models/aliascompletionmodel.h"
50#include "ui/models/loadedaccountmodel.h"
51
52
53VCMain::VCMain(QWidget* parent, Bootstrap* b)
54    : QMainWindow(parent)
55    , bootstrap_(b)
56    , recipientAddingEnabled_(true)
57{
58        ui.setupUi(this);
59
60        ui.lblSMSSent->hide();
61
62        /* Accounts */
63    accountModel_       = new AccountTreeModel(this, true);
64        accountFilterModel_ = new LoadedAccountModel(this);
65        accountFilterModel_->setSourceModel(accountModel_);
66        accountFilterModel_->setSortCaseSensitivity(Qt::CaseInsensitive);
67        accountFilterModel_->setDynamicSortFilter(true);
68    accountFilterModel_->sort(AccountTreeModel::ColName);
69        ui.lstAccounts->setModel(accountFilterModel_);
70        ui.lstAccounts->setModelColumn(AccountTreeModel::ColNameWFreeCount);
71    connect(ui.lstAccounts->model(), SIGNAL(layoutChanged()),
72            this, SLOT(onAccountRowInserted()));
73
74        /* Contact / Groups */
75        contactGroupListModel_ = new ContactGroupListModel(this);
76        contactGroupSortModel_ = new QSortFilterProxyModel(this);
77        contactGroupSortModel_->setSourceModel(contactGroupListModel_);
78        contactGroupSortModel_->setDynamicSortFilter(true);
79        contactGroupSortModel_->setSortCaseSensitivity(Qt::CaseInsensitive);
80        contactGroupSortModel_->sort(0, Qt::AscendingOrder);
81    ui.lstContacts->setModel(contactGroupSortModel_);
82
83        QSortFilterProxyModel* completionModel = new AliasCompletionModel(this);
84    completionModel->setSourceModel(contactGroupListModel_);
85    BetterCompleter* aliasCompleter = new BetterCompleter(completionModel, this);
86    aliasCompleter->setCompletionMode(QCompleter::PopupCompletion);
87    aliasCompleter->setCaseSensitivity(Qt::CaseInsensitive);
88    //aliasCompleter->popup()->setIconSize(QSize(32, 42));
89
90    //ui.lstContacts->setCompleter(new QCompleter(completionModel));
91    ui.lstContacts->setCompleter(aliasCompleter);
92    ui.lstContacts->view()->setIconSize(QSize(24, 31)); // The icon size on the drop down
93
94    connect(ui.lstContacts->lineEdit(), SIGNAL(returnPressed()),
95            this, SLOT(on_lstContacts_returnPressed()));
96    connect(ui.lstContacts, SIGNAL(activated(int)),
97            this, SLOT(on_btnAddRecipient_clicked()));
98    connect(ui.lstContacts->completer(), SIGNAL(activated(const QString&)),
99            this, SLOT(on_lstContacts_completerActivated(const QString&)));
100
101    connect(BCAccountManager::instance(), SIGNAL(accountLoginStateChanged(IAccount*)),
102            this, SLOT(onAccountLoginStateChanged(IAccount*)));
103    connect(BCAccountInitManager::instance(), SIGNAL(accountInitFailed(IAccount*, const EException&)),
104            this, SLOT(onAccountInitFailed(IAccount*, const EException&)));
105
106    connect(b, SIGNAL(accountsLoaded(bool)),
107            this, SLOT(onAccountsLoaded(bool)));
108
109    connect(BCSettings::instance(), SIGNAL(settingChanged(Settings::Setting)),
110            this, SLOT(onSettingChanged(Settings::Setting)));
111
112
113    TaskStatusBar* tsb = new TaskStatusBar();
114    ui.statusbar->addPermanentWidget(tsb);
115
116
117    // Initialize the form
118    on_treeRecipients_itemSelectionChanged();
119    enableSendBtnIfAllFilled();
120
121    // Set the Ctrl+W shortcut
122    new QShortcut(QKeySequence("Ctrl+W"), this, SLOT(close()));
123
124    recalculateSMSCosts();
125    setShortcuts();
126
127        ui.lstContacts->setCurrentIndex(-1);
128
129        if (BCSettings::instance()->getCheckForUpdates()) {
130        if (BCUpdateManager::instance()->isUpdateAvailable(BCUpdateManager::utEdge)) {
131            onUpdateAvailable(BCUpdateManager::instance()->newestVersion(BCUpdateManager::utEdge), BCUpdateManager::utEdge);
132        } else {
133            connect(BCUpdateManager::instance(), SIGNAL(updateAvailable(const SVersion&, BCUpdateManager::UpdateType)),
134                    this, SLOT(onUpdateAvailable(const SVersion&, BCUpdateManager::UpdateType)));
135        }
136        }
137
138    BCGuiManager::instance()->setMainMenu(IGuiManager::File, ui.menuFile, ui.actionExit);
139    BCGuiManager::instance()->setMainMenu(IGuiManager::Edit, ui.menuEdit, ui.actionPreferences);
140    BCGuiManager::instance()->setMainMenu(IGuiManager::Help, ui.menuHelp, ui.actionAbout);
141
142    QTimer::singleShot(500, this, SLOT(checkForAccounts()));
143}
144
145/**
146 * Check if an account is already created or show the account creation dialog otherwise.
147 */
148void VCMain::checkForAccounts() {
149    if (BCGatewayManager::instance()->getGatewayList().size() == 0) {
150        // If no gateway is there, then abort.
151        return;
152    }
153
154    if (BCAccountManager::instance()->getAccountList().size() == 0) {
155        VCEditAccount* ea = new VCEditAccount(this, NULL);
156        if (ea->exec() == QDialog::Accepted){ // Wait for return
157            BCAccountManager::instance()->saveAccount(ea->account());
158        }
159        delete ea;
160    }
161}
162
163void VCMain::changeEvent(QEvent* event) {
164    if (event->type() == QEvent::LanguageChange) {
165        ui.retranslateUi(this);
166        recalculateSMSCosts(); // Display costs in the new language
167    }
168    QMainWindow::changeEvent(event);
169}
170
171IAccount* VCMain::selectedAccount() const {
172    QModelIndex idx = accountFilterModel_->mapToSource(accountFilterModel_->index(ui.lstAccounts->currentIndex(), 0));
173    return accountModel_->dataObject(idx);
174}
175
176
177void VCMain::setShortcuts() {
178    // Remove the old shortcuts
179    foreach (QShortcut* shortcut, shortcuts_) {
180        shortcuts_.remove(shortcut);
181        delete shortcut;
182    }
183
184    // Set the new ones
185    shortcuts_.insert(new QShortcut(BCSettings::instance()->getNewMessageShortCut(),
186                                    this, SLOT(on_shortcutNewMessage())));
187    shortcuts_.insert(new QShortcut(BCSettings::instance()->getClearMessageTextShortCut(),
188                                    this, SLOT(on_shortcutClearMessageText())));
189    shortcuts_.insert(new QShortcut(BCSettings::instance()->getClearRecipientsShortCut(),
190                                    this, SLOT(on_shortcutClearRecipients())));
191    shortcuts_.insert(new QShortcut(BCSettings::instance()->getSendShortCut(),
192                                    this, SLOT(on_shortcutSendMessage())));
193}
194
195
196/* Contacts & Recipients... */
197bool VCMain::isContactNode(const QTreeWidgetItem* node){
198    return nodeToContact.contains(const_cast<QTreeWidgetItem*>(node));
199}
200bool VCMain::isGroupNode(const QTreeWidgetItem* node){
201    return nodeToGroup.contains(const_cast<QTreeWidgetItem*>(node));
202}
203
204SContact VCMain::getContactOfNode(const QTreeWidgetItem* node){
205    if (!isContactNode(node)){
206        return NULL;
207    } else {
208        return nodeToContact.value(const_cast<QTreeWidgetItem*>(node));
209    }
210}
211SGroup VCMain::getGroupOfNode(const QTreeWidgetItem* node){
212    if (!isGroupNode(node)){
213        return NULL;
214    } else {
215        return nodeToGroup.value(const_cast<QTreeWidgetItem*>(node));
216    }
217}
218
219bool VCMain::isNodeContactOrHasContact(const QTreeWidgetItem* node, const SContact& contact){
220    if (isContactNode(node)){
221        SContact contact_ = getContactOfNode(node);
222        if (contact == contact_){
223            return true;
224        }
225    } else {
226        // group...
227        for (int x = 0; x < node->childCount(); ++x){
228            if (isNodeContactOrHasContact(node->child(x), contact)){
229                return true;
230            }
231        }
232    }
233    return false;
234
235}
236
237bool VCMain::isContactAlreadyRecipient(const SContact& contact){
238    return getRecipientContacts(true).contains(contact);
239}
240bool VCMain::isGroupAlreadyRecipient(const SGroup& group){
241    return getRecipientGroups().contains(group);
242}
243
244QSet<SContact> VCMain::getRecipientContacts(bool withGroupContacts /* = true */, QTreeWidgetItem* node /* = NULL */) {
245    QSet<SContact> result;
246
247    if (node == NULL) {
248        for (int i = 0; i < ui.treeRecipients->topLevelItemCount(); ++i) {
249            result.unite(getRecipientContacts(withGroupContacts, ui.treeRecipients->topLevelItem(i)));
250        }
251    }
252
253    if (isContactNode(node)) {
254        result.insert(getContactOfNode(node));
255    } else if (withGroupContacts && isGroupNode(node)) {
256        for (int i = 0; i < node->childCount(); ++i) {
257            result.unite(getRecipientContacts(withGroupContacts, node->child(i)));
258        }
259    }
260
261    return result;
262}
263
264QSet<SGroup> VCMain::getRecipientGroups() {
265    QSet<SGroup> result;
266    for (int x = 0; x < ui.treeRecipients->topLevelItemCount(); ++x){
267        if (isGroupNode(ui.treeRecipients->topLevelItem(x))){
268            result.insert(getGroupOfNode(ui.treeRecipients->topLevelItem(x)));
269        }
270    }
271    return result;
272}
273
274
275void VCMain::addRecipient(const SContact& contact, QTreeWidgetItem* parent /* = NULL */){
276    if (!contact || isContactAlreadyRecipient(contact)){
277        return;
278    }
279
280    // TODO: Check if the given recipient/number is a valid recipient for the selected gateway
281
282    contactGroupListModel_->addFilteredContact(contact);
283
284    QTreeWidgetItem* node;
285    if (parent) {
286        node = new QTreeWidgetItem(parent); // parent->addChild is done in here
287    } else {
288        node = new QTreeWidgetItem(ui.treeRecipients);
289        ui.treeRecipients->addTopLevelItem(node);
290    }
291
292    node->setText(0, contact.name());
293    node->setIcon(0, QPixmap::fromImage(contact.image()));
294    nodeToContact.insert(node, contact);
295}
296
297void VCMain::addRecipient(const SGroup& group){
298    if (!group || isGroupAlreadyRecipient(group)){
299        return;
300    }
301
302    QTreeWidgetItem* node = new QTreeWidgetItem(ui.treeRecipients);
303    ui.treeRecipients->addTopLevelItem(node);
304
305    node->setText(0, group.name());
306    node->setIcon(0, QPixmap::fromImage(group.image()));
307    nodeToGroup.insert(node, group);
308
309    foreach (SContact contact, group.contacts()) {
310        addRecipient(contact, node);
311    }
312}
313
314void VCMain::removeNode(QTreeWidgetItem* node){
315    QTreeWidgetItem* parent = node->parent();
316    if (parent){
317        parent->removeChild(node);
318
319        if (parent->childCount() == 0){
320            removeRecipient(parent);
321        }
322    } else {
323        ui.treeRecipients->takeTopLevelItem(ui.treeRecipients->indexOfTopLevelItem(node));
324    }
325}
326void VCMain::removeRecipient(QTreeWidgetItem* node){
327    if (isContactNode(node)){
328        SContact contact = nodeToContact.value(node);
329        contactGroupListModel_->removeFilteredContact(contact);
330
331        removeNode(node);
332        nodeToContact.remove(node);
333    } else { // Group
334        for (int x = 0; x < node->childCount(); ++x){
335            removeRecipient(node->child(x)); // Remove all contacts of this group
336        }
337
338        removeNode(node);
339        nodeToGroup.remove(node);
340    }
341}
342
343bool VCMain::isAllFilled() {
344    return (ui.txtMessage->toPlainText().trimmed() != "")
345            && (ui.treeRecipients->topLevelItemCount() > 0)
346            && (ui.lstAccounts->currentIndex() > -1);
347}
348void VCMain::enableSendBtnIfAllFilled() {
349    ui.btnSend->setEnabled(this->isAllFilled());
350}
351
352
353void VCMain::clearMessage() {
354    ui.txtMessage->clear();
355    ui.txtMessage->setFocus();
356}
357void VCMain::clearRecipients() {
358    while (ui.treeRecipients->topLevelItemCount() > 0) {
359        removeRecipient(ui.treeRecipients->topLevelItem(0));
360    }
361}
362
363void VCMain::sendMessage() {
364    if (!this->isAllFilled()) {
365        return;
366    }
367
368    IAccount* account         = selectedAccount();
369    QString message           = ui.txtMessage->toPlainText().trimmed() +
370                                 BCSuffixManager::instance()->suffixIfEnabled();
371    QSet<SContact> recipients = getRecipientContacts(true);
372
373    if (account) {
374        ISMSSendTask* task = account->createSMSSendTask(message, recipients);
375
376        if (task) {
377            connect(task, SIGNAL(exceptionOccured(STask*)),
378                    this, SLOT(onSMSSendingErrorOccured(STask*)), Qt::DirectConnection);
379            connect(task, SIGNAL(finished(STask*)),
380                    this, SLOT(onSMSSendingFinished(STask*)), Qt::DirectConnection);
381
382            QDialog* sd = BCGuiManager::instance()->createNewSendingDialog(this, task);
383
384            task->start();
385
386            sd->exec();
387            delete sd;
388        }
389    }
390}
391
392
393/* SLOTS... */
394
395void VCMain::on_btnSend_clicked() {
396    sendMessage();
397}
398
399void VCMain::on_treeRecipients_itemSelectionChanged(){
400    ui.btnRemoveRecipient->setEnabled(ui.treeRecipients->selectedItems().count() > 0);
401}
402
403void VCMain::on_lstContacts_editTextChanged(const QString& text) {
404    if (text == "") {
405        ui.lstContacts->hidePopup();
406        ui.lstContacts->setCurrentIndex(-1);
407    }
408}
409void VCMain::on_lstContacts_returnPressed() {
410    if (ui.lstContacts->currentIndex() < 0) {
411        SNumber number(ui.lstContacts->lineEdit()->text().trimmed(), SNumber::GuessFormat);
412        if (!number.isValid()) {
413            // If nothing is selected in the completion, just use the topmost completion
414            ui.lstContacts->completer()->setCurrentRow(0);
415            ui.lstContacts->lineEdit()->setText(ui.lstContacts->completer()->currentCompletion());
416        } else {
417            // There was entered a valid number, so do not select any completion but search after the number.
418            on_btnAddRecipient_clicked();
419        }
420    }
421}
422void VCMain::on_lstContacts_completerActivated(const QString& text) {
423    Q_UNUSED(text);
424    if (ui.lstContacts->completer()->currentRow() >= 0) {
425        if (ui.lstContacts->currentIndex() == -1) {
426            ui.lstContacts->setCurrentIndex(ui.lstContacts->findText(ui.lstContacts->currentText()));
427        }
428        QTimer::singleShot(0, this, SLOT(on_btnAddRecipient_clicked()));
429    }
430}
431
432void VCMain::on_btnAddRecipient_clicked(){
433    if (!recipientAddingEnabled_) return;
434    recipientAddingEnabled_ = false; // Ignore multiple calls of btnAddRecipient-clicked events
435
436    QModelIndex idx = contactGroupSortModel_->mapToSource(contactGroupSortModel_->index(ui.lstContacts->currentIndex(), 0));
437    if (idx.isValid()) {
438        ContactGroupContainer recipientCntr = contactGroupListModel_->dataObject(idx);
439        if (recipientCntr.isContact) {
440            addRecipient(recipientCntr.contact);
441        } else {
442            addRecipient(recipientCntr.group);
443        }
444    } else {
445        SNumber number(ui.lstContacts->lineEdit()->text().trimmed(), SNumber::GuessFormat);
446        if (number.isValid()) {
447            SContact recipient = BCContactManager::instance()->getContactByNumber(number);
448
449            if (recipient) {
450                addRecipient(recipient);
451            } else {
452                SContact recipient;
453                recipient.setNumber(number);
454
455                if (QMessageBox::Yes == QMessageBox::question(this, tr("SMSSender"),
456                                                              tr("This number is not yet in your address book. Do you want to add it?"),
457                                                              QMessageBox::Yes | QMessageBox::No,
458                                                              QMessageBox::Yes)) {
459                    VCEditContact* ec = new VCEditContact(this, recipient, false);
460                    if (ec->exec() == QDialog::Accepted){ // Wait for return
461                        BCContactManager::instance()->saveContact(recipient);
462                    }
463                    delete ec;
464                }
465                if (recipient.name() == "") {
466                    recipient.setName(number.toString(SNumber::IsoFormatShort));
467                }
468                addRecipient(recipient);
469            }
470        }
471    }
472    ui.lstContacts->setCurrentIndex(-1);
473    // Clear the text in the edit, even if the completer is messing around
474    QTimer::singleShot(0, ui.lstContacts->lineEdit(), SLOT(clear()));
475
476    enableSendBtnIfAllFilled();
477
478    QTimer::singleShot(20, this, SLOT(reenableRecipientAdding()));
479}
480void VCMain::reenableRecipientAdding() {
481    recipientAddingEnabled_ = true;
482}
483
484void VCMain::on_btnRemoveRecipient_clicked(){
485    QListIterator<QTreeWidgetItem*> i(ui.treeRecipients->selectedItems());
486    while (i.hasNext()){
487        removeRecipient(i.next());
488    }
489    enableSendBtnIfAllFilled();
490}
491
492
493/* File menu */
494
495void VCMain::on_actionNewMessage_triggered(bool checked) {
496    Q_UNUSED(checked);
497
498    clearMessage();
499    clearRecipients();
500}
501
502/* Edit menu */
503
504void VCMain::on_actionAccounts_triggered(bool checked) {
505    Q_UNUSED(checked);
506
507    VCAccountList* al = new VCAccountList(this);
508    al->exec();
509    delete al;
510}
511
512void VCMain::on_actionAddressBook_triggered(bool checked){
513    Q_UNUSED(checked);
514
515    VCAddressBook* ab = new VCAddressBook(this);
516    ab->exec();
517    delete ab;
518}
519
520void VCMain::on_actionPreferences_triggered(bool checked){
521    Q_UNUSED(checked);
522
523    VCSettings* s = new VCSettings(this);
524        s->exec();
525        delete s;
526}
527
528
529/* Help menu */
530
531void VCMain::on_actionAbout_triggered(bool checked){
532    Q_UNUSED(checked);
533
534    VCAbout* a = new VCAbout(this);
535    a->exec();
536    delete a;
537}
538
539
540void VCMain::recalculateSMSCosts() const {
541    IAccount* account = selectedAccount();
542
543    int i = 0;
544
545    QString msg = ui.txtMessage->toPlainText().trimmed();
546    if (!msg.isEmpty()) {
547        i = 1;
548        if (account) {
549            i = account->costsForText(msg + BCSuffixManager::instance()->suffixIfEnabled());
550        }
551    }
552    ui.lblTextSize->setText(tr("%1 SMS").arg(i));
553}
554
555
556void VCMain::on_txtMessage_textChanged() {
557    ui.lblSMSSent->hide();
558    recalculateSMSCosts();
559    enableSendBtnIfAllFilled();
560}
561
562void VCMain::on_lstAccounts_currentIndexChanged(int index) {
563    Q_UNUSED(index);
564
565    recalculateSMSCosts();
566    enableSendBtnIfAllFilled();
567}
568
569
570/* Shortcuts */
571
572void VCMain::on_shortcutNewMessage() {
573    clearMessage();
574    clearRecipients();
575}
576
577void VCMain::on_shortcutClearMessageText() {
578    clearMessage();
579}
580
581void VCMain::on_shortcutClearRecipients() {
582    clearRecipients();
583}
584
585void VCMain::on_shortcutSendMessage() {
586    sendMessage();
587}
588
589
590
591/* Settings */
592
593void VCMain::onSettingChanged(Settings::Setting setting) {
594    switch (setting) {
595        case Settings::AddSuffix:
596        case Settings::SMSSuffix:
597            recalculateSMSCosts();
598            break;
599
600        case Settings::ShortcutNewMessage:
601        case Settings::ShortcutClearMessageText:
602        case Settings::ShortcutCleanRecipients:
603        case Settings::ShortcutSend:
604            setShortcuts();
605            break;
606
607        default:
608            break;
609    }
610}
611
612
613
614/* Account loading */
615void VCMain::onAccountLoginStateChanged(IAccount* account) {
616    Q_UNUSED(account);
617
618    enableSendBtnIfAllFilled();
619}
620
621void VCMain::onAccountInitFailed(IAccount* account, const EException& exception) {
622    qWarning() << exception.chainedWhat();
623    BCGuiManager::instance()->execErrorDialog(tr("An error occured while initializing the account \"%1\".").arg(account->name()), exception);
624}
625
626void VCMain::onAccountsLoaded(bool hadErrors) {
627    if (!hadErrors) {
628        return;
629    }
630
631    QString errorMsg;
632    QString detailedMsg;
633    foreach(SDummyAccount* account, bootstrap_->erroneousAccounts.keys()) {
634        const EException* ex = bootstrap_->erroneousAccounts.value(account);
635        errorMsg += QString("[%1]: %2\n").arg(account->name(), ex->unchainedWhat());
636        if (ex->hasChainedException()) {
637            detailedMsg += QString("[%1]: %2\n").arg(account->name(), ex->chainedException().chainedWhat());
638        }
639    }
640    errorMsg.remove(QRegExp("\n$"));
641    detailedMsg.remove(QRegExp("\n$"));
642
643    QMessageBox msg(QMessageBox::Warning, tr("Error occured"),
644                    tr("Errors occured while loading your accounts."), QMessageBox::Ok, this);
645    msg.setDefaultButton(QMessageBox::Ok);
646    msg.setInformativeText(errorMsg);
647    msg.setDetailedText(detailedMsg);
648    msg.exec();
649}
650
651void VCMain::onAccountRowInserted() {
652    if (ui.lstAccounts->count() <= 0) {
653        return;
654    }
655
656    if ((ui.lstAccounts->currentIndex() == -1)
657            || (ui.lstAccounts->currentIndex() >= (ui.lstAccounts->count() - 1))) {
658        // No account selected, but one is loaded now -> autoselect one
659        ui.lstAccounts->setCurrentIndex(ui.lstAccounts->count() - 1);
660    }
661}
662
663void VCMain::onSMSSendingFinished(STask* task) {
664    metaObject()->invokeMethod(this, "smsSendingFinished", Qt::QueuedConnection, Q_ARG(STask::Result, task->taskResult()));
665}
666void VCMain::smsSendingFinished(STask::Result taskResult) {
667    Q_ASSERT(QThread::currentThread() == thread());
668
669    if (taskResult == STask::rSuccess) {
670        ui.lblSMSSent->show();
671
672        if (BCSettings::instance()->getShowSentConfirmation()) {
673            QMessageBox::information(this, tr("SMS sent"),
674                                     tr("The sms has been sent."),
675                                     QMessageBox::Ok, QMessageBox::Ok);
676        }
677    }
678}
679
680void VCMain::onSMSSendingErrorOccured(STask* task) {
681    metaObject()->invokeMethod(this, "smsSendingErrorOccured", Qt::QueuedConnection, Q_ARG(const EException&, task->exception()));
682}
683void VCMain::smsSendingErrorOccured(const EException &exception) {
684    Q_ASSERT(QThread::currentThread() == thread());
685
686    qWarning() << exception.chainedWhat();
687    BCGuiManager::instance()->execErrorDialog(tr("An error occured while sending the sms."), exception);
688}
689
690
691void VCMain::onUpdateAvailable(const SVersion& newVersion, BCUpdateManager::UpdateType type) {
692    Q_UNUSED(type);
693
694    VCUpdateDialog* d = new VCUpdateDialog(this, newVersion);
695    d->exec();
696    delete d;
697}
Note: See TracBrowser for help on using the repository browser.