source: SMSSender/src/business/bcaccountinitmanager.cpp @ 240:936dde048c4e

Last change on this file since 240:936dde048c4e was 240:936dde048c4e, checked in by Sämy Zehnder <saemy.zehnder@…>, 8 years ago
  • Using Qt::DirectConnection? for all slots on STask to ensure liveness of the STask* parameter.
File size: 2.9 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 "bcaccountinitmanager.h"
19
20#include <QString>
21#include <QSet>
22
23#include <iaccount_tasks.h>
24#include <managers/staskmanager.h>
25
26S_SINGLETON_IMPL(BCAccountInitManager)
27
28BCAccountInitManager::BCAccountInitManager()
29    : IAccountInitManager(NULL) // singleton
30{
31}
32
33/**
34 * Starts the initialization process of the given account and connects
35 * the signals to it.
36 * If the account is already initialized, nothing happens.
37 * If the account is already initializing, we only connect to the signals, if not already done
38 *
39 * @param account The to be initialized account
40 */
41void BCAccountInitManager::initAccount(IAccount* account) {
42    if (initializingAccounts_.contains(account)) {
43        // The initialization of this account is already under our control
44        return;
45    }
46
47    if (!account->isEnabled()) {
48        return;
49    }
50    if (account->isInitialized()) {
51        return;
52    }
53
54    IAccountInitTask* initTask = account->createInitTask();
55    if (initTask) {
56        initializingAccounts_.insert(account);
57
58        connect(initTask, SIGNAL(finished(STask*)),
59                this, SLOT(onAccountInitFinished(STask*)), Qt::DirectConnection);
60        connect(initTask, SIGNAL(exceptionOccured(STask*)),
61                this, SLOT(onAccountInitFailed(STask*)), Qt::DirectConnection);
62        connect(account, SIGNAL(initStateChanged(IAccount*)),
63                this, SIGNAL(accountInitStateChanged(IAccount*)));
64
65        initTask->start();
66    }
67}
68
69/**
70 * Starts the initialization process of the given accounts.
71 *
72 * @param accounts The to be initialized accounts
73 */
74void BCAccountInitManager::initAccounts(const QSet<IAccount*>& accounts) {
75    foreach (IAccount* account, accounts) {
76        initAccount(account);
77    }
78}
79
80
81void BCAccountInitManager::onAccountInitFinished(STask* task) {
82    IAccount* account = static_cast<IAccountInitTask*>(task)->account();
83
84    initializingAccounts_.remove(account);
85    emit accountInitFinished(account, task->taskResult());
86}
87void BCAccountInitManager::onAccountInitFailed(STask* task) {
88    IAccount* account = static_cast<IAccountInitTask*>(task)->account();
89
90    emit accountInitFailed(account, task->exception());
91}
Note: See TracBrowser for help on using the repository browser.