2 * Copyright (C) 2011, Jamie Thompson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; If not, see
16 * <http://www.gnu.org/licenses/>.
19 #include "RestoreAccountStateWindow.h"
21 #include "CellularRadio.h"
22 #include "ModeWindow.h"
27 using namespace Windows;
29 RestoreAccountStateWindow::RestoreAccountStateWindow(Settings &settings, QWidget *parent) :
30 BaseWindow(settings, parent)
32 if(CellularRadio::CurrentState() == false && NumEnabledAccounts() == 0)
38 void RestoreAccountStateWindow::CreateContents()
40 switch(CurrentSettings().AppMode())
42 case Settings::APPMODE_GUI:
44 QVBoxLayout *layout = new QVBoxLayout();
46 layout->setMargin(40);
48 QLabel *lblNotice1 = new QLabel(tr("You have no enabled accounts and the cellular modem is disabled. If this was the result of the last crash of this program, please restore them as you wish."));
49 lblNotice1->setAlignment(Qt::AlignCenter);
50 lblNotice1->setWordWrap(true);
51 layout->addWidget(lblNotice1, 1);
53 QLabel *lblNotice2 = new QLabel(tr("Once you have enabled things as you want them, tap next to proceed."));
54 lblNotice2->setWordWrap(true);
55 lblNotice2->setAlignment(Qt::AlignCenter);
56 layout->addWidget(lblNotice2, 1);
58 QHBoxLayout *layoutButtons = new QHBoxLayout();
60 QPushButton* btnToggleModem = new QPushButton(tr("Toggle Cellular Modem"));
61 QObject::connect(btnToggleModem, SIGNAL(clicked()), this, SLOT(ToggleModem()));
62 layoutButtons->addWidget(btnToggleModem);
63 layoutButtons->setAlignment(btnToggleModem, Qt::AlignHCenter);
65 QLabel *lblSpacer = new QLabel();
66 layoutButtons->addWidget(lblSpacer);
67 layoutButtons->setAlignment(lblSpacer, Qt::AlignHCenter | Qt::AlignVCenter);
69 QPushButton* btnSetAccountStatus = new QPushButton(tr("Set Account Status"));
70 QObject::connect(btnSetAccountStatus, SIGNAL(clicked()), this, SLOT(SetAccountStatus()));
71 layoutButtons->addWidget(btnSetAccountStatus);
72 layoutButtons->setAlignment(btnSetAccountStatus, Qt::AlignHCenter);
74 layout->addLayout(layoutButtons);
76 QPushButton* btnProceed = new QPushButton(tr("Next"));
77 QObject::connect(btnProceed, SIGNAL(clicked()), this, SLOT(Proceed()));
78 layout->addWidget(btnProceed);
79 layout->setAlignment(btnProceed, Qt::AlignHCenter);
81 centralWidget()->setLayout(layout);
87 case Settings::APPMODE_CONSOLE:
97 void RestoreAccountStateWindow::ToggleModem()
99 CellularRadio::Toggle();
102 void RestoreAccountStateWindow::SetAccountStatus()
104 const char * NOKIA_SERVICE_ACCOUNTS_UI("com.nokia.AccountsUI");
105 const char * NOKIA_PATH_ACCOUNTS_UI("/com/nokia/AccountsUI");
106 const char * NOKIA_IFACE_ACCOUNTS_UI("com.nokia.Accounts");
108 QDBusMessage msg(QDBusMessage::createMethodCall(NOKIA_SERVICE_ACCOUNTS_UI, NOKIA_PATH_ACCOUNTS_UI, NOKIA_IFACE_ACCOUNTS_UI, "OpenAccountsList"));
109 msg << (uint)winId();
110 QDBusConnection::sessionBus().call(msg);
113 void RestoreAccountStateWindow::Proceed()
118 void RestoreAccountStateWindow::Advance()
120 QWidget* next = new Windows::ModeWindow(CurrentSettings());
125 const uint RestoreAccountStateWindow::NumEnabledAccounts()
127 const char * TP_ACCOUNT_PHONE("/org/freedesktop/Telepathy/Account/ring/tel/ring");
128 const char * TP_IFACE_ACCOUNT("org.freedesktop.Telepathy.Account");
129 const char * TP_IFACE_ACCOUNT_MANAGER("org.freedesktop.Telepathy.AccountManager");
130 const char * TP_PATH_ACCOUNT_MANAGER("/org/freedesktop/Telepathy/AccountManager");
131 const char * TP_IFACE_DBUS_PROPERTIES("org.freedesktop.DBus.Properties");
133 uint numEnabledAccounts(0);
135 QDBusInterface tpAccountManager(TP_IFACE_ACCOUNT_MANAGER, TP_PATH_ACCOUNT_MANAGER, TP_IFACE_DBUS_PROPERTIES);
136 if (tpAccountManager.isValid())
139 QDBusMessage accountList = tpAccountManager.call("Get", TP_IFACE_ACCOUNT_MANAGER, "ValidAccounts");
140 foreach (QVariant arg, accountList.arguments())
142 const QDBusArgument argument(qvariant_cast<QDBusVariant>(arg).variant().value<QDBusArgument>());
143 argument.beginArray();
144 while (!argument.atEnd())
146 // Grab the account path
147 QDBusObjectPath accountPath;
148 argument >> accountPath;
150 // Ignore the phone account
151 if(accountPath.path() == TP_ACCOUNT_PHONE)
155 // Grab the enabled property of each account
156 QDBusInterface tpAccount(TP_IFACE_ACCOUNT_MANAGER, accountPath.path(), TP_IFACE_DBUS_PROPERTIES);
157 if (tpAccount.isValid())
159 QDBusReply<QVariant> isEnabledProp = tpAccount.call("Get", TP_IFACE_ACCOUNT, "Enabled");
161 if(isEnabledProp.value().toBool())
162 ++numEnabledAccounts;
170 return numEnabledAccounts;