Renamed some setters for consistency.
[qwerkisync] / CellularRadio.cpp
1 /*
2  * Copyright (C) 2011, Jamie Thompson
3  *
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.
8  *
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.
13  *
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/>.
17  */
18
19 #include "CellularRadio.h"
20
21 #include <QDebug>
22
23 #include <QtDBus>
24
25 #include <stdexcept>
26
27 const char * NOKIA_SERVICE_PHONE_SCC("com.nokia.phone.SSC");
28 const char * NOKIA_PATH_PHONE_SCC("/com/nokia/phone/SSC");
29 const char * NOKIA_IFACE_PHONE_SCC("com.nokia.phone.SSC");
30
31 bool CellularRadio::CurrentState()
32 {
33         QDBusInterface nokiaPhone(NOKIA_SERVICE_PHONE_SCC, NOKIA_PATH_PHONE_SCC, NOKIA_IFACE_PHONE_SCC, QDBusConnection::systemBus());
34         if (nokiaPhone.isValid())
35         {
36                 QDBusReply<QString> isEnabledReply = nokiaPhone.call("get_modem_state");
37                 if(isEnabledReply.isValid())
38                 {
39                         bool isEnabled(isEnabledReply.value() == "online" || isEnabledReply.value() == "actvation_pending");
40                         qDebug() << (isEnabled ? "Enabled:\t\t" : "Not enabled:\t") << "Cellular";
41                         return isEnabled;
42                 }
43                 else
44                         qDebug() << isEnabledReply.error();
45         }
46         else
47                 qDebug() << nokiaPhone.lastError();
48
49         throw std::runtime_error("Unable to query cellular modem state");
50 }
51
52 void CellularRadio::SetState(bool shouldRadioBeEnabled)
53 {
54         QDBusInterface nokiaPhone(NOKIA_SERVICE_PHONE_SCC, NOKIA_PATH_PHONE_SCC, NOKIA_IFACE_PHONE_SCC, QDBusConnection::systemBus());
55         if (nokiaPhone.isValid())
56         {
57                 QDBusReply<void> disableModemReply = nokiaPhone.call("set_radio", shouldRadioBeEnabled);
58
59                 if(!disableModemReply.isValid())
60                         qDebug() << disableModemReply.error().message();
61         }
62         else
63                 qDebug() << nokiaPhone.lastError().message();
64 }