Merge branch 'master' of ssh://drop.maemo.org/git/vicar
[vicar] / src / vicar-utils / cpp / main.cpp
1 /*
2 @version: 0.6
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 #include "telepathyutility.h"
8 #include "databaseutility.h"
9 #include "vicarprofiletypes.h"
10 #include "connectioninterfacerequeststypes.h"
11 #include "harmattanaccountutility.h"
12 #include <QDebug>
13 <<<<<<< HEAD
14 #include <QCoreApplication>
15 #include "dbusutility.h"
16 #include <QDBusMetaType>
17 #include <QDBusConnection>
18 #include <QCryptographicHash> //DEBUG
19
20
21 #include <QDBusInterface>
22 #include <QDBusObjectPath>
23 #include <QDBusArgument>
24
25 #define AM_SERVICE          "org.freedesktop.Telepathy.AccountManager"
26 #define AM_OBJ_PATH         "/org/freedesktop/Telepathy/AccountManager"
27 #define AM_INTERFACE        "org.freedesktop.Telepathy.AccountManager"
28 #define RING_CONN_SERVICE   "org.freedesktop.Telepathy.Connection.ring.tel.ring"
29 #define RING_CONN_PATH      "/org/freedesktop/Telepathy/Connection/ring/tel/ring"
30 #define DBUS_SERVICE        "org.freedesktop.DBus.Properties"
31 #define DBUS_OBJ_PATH       "/org/freedesktop/DBus/Properties"
32 #define DBUS_PROPS_IFACE     "org.freedesktop.DBus.Properties"
33 =======
34 #include <QCoreApplication> //DEBUG - Delete this
35 #include "dbusutility.h"
36 #include <QDBusMetaType>
37 #include <QDBusConnection>
38 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
39
40 int main(int argc, char *argv[])
41 {
42
43     QCoreApplication app(argc,argv);
44
45     qDBusRegisterMetaType<org::freedesktop::Telepathy::SimplePresence>();
46     //From Connection Interface Requests
47     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetails>();
48     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetailsList>();
49     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClass>();
50     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClassList>();
51     //From Vicar Profile Types
52     //qDBusRegisterMetaType<org::maemo::vicar::Profile>();
53     //qDBusRegisterMetaType<org::maemo::vicar::ProfileList>();
54
55     TelepathyUtility *tpUtility = new TelepathyUtility();
56     DatabaseUtility *databaseUtility = new DatabaseUtility();
57     HarmattanAccountUtility *accountUtility = new HarmattanAccountUtility();
58
59     if (argc > 1 && argv[1]){
60         QString instruction = QString(argv[1]);
61         if (instruction == "INSTALL"){
62             //Check if Account already exists                                                            
63             if (!tpUtility->accountExists()){
64                 qDebug() << "VICaR account not found. Creating ..";
65                 bool result = tpUtility->createAccount();
66                 if (!result) exit(1);
67             }
68             else{
69                 qDebug() << "VICaR account found.";
70             }
71         }
72         else if (instruction == "REMOVE"){
73             bool result = tpUtility->deleteAccount();
74             if (!result) exit(2);
75         }
76         else if (instruction == "TESTING"){
77             tpUtility->callNumberWithRing(argv[2]);
78         }
79         else if (instruction == "TPACCOUNTSTATUS"){
80             QString status = tpUtility->getAccountStatus();
81             qDebug() << "Account Status is "<< status;
82         }
83 #if defined(Q_WS_MAEMO_5)
84         else if (instruction == "CREATEDB"){
85             bool result = databaseUtility->openDatabase();
86             if (!result){
87                 qDebug() <<"Error creating vicar database. "
88                         <<databaseUtility->lastError();
89                 exit(3);
90             }
91
92             qDebug() << "VICaR database opened.";
93             qDebug() << "Preparing VICaR tables..";
94             result = databaseUtility->prepareTables();
95             if (!result){
96                 qDebug() <<"Error creating tables. "
97                         <<databaseUtility->lastError();
98                 exit(4);
99             }
100
101             databaseUtility->closeDatabase();
102         }
103         else if (instruction == "DROPDB"){
104             bool result = databaseUtility->deleteDatabase();
105             if (!result){
106                 qDebug() <<"Error deleting vicar database. "
107                         <<databaseUtility->lastError();
108                 exit(5);
109             }
110             qDebug() << "VICaR database deleted.";
111         }    
112 #elif defined(Q_WS_MAEMO_6)
113         else if (instruction == "--create-account"){
114             qDebug() << "Creating account";
115             accountUtility->addAccount();
116         }
117 <<<<<<< HEAD
118         else if (instruction == "--delete-account"){
119             qDebug() << "Deleting account";
120             accountUtility->removeAccount();
121         }
122 #endif
123         else {
124             qDebug() << "This command is not recognized";
125         }
126     }
127     else{                        
128 =======
129         else if (instruction == "TPACCOUNTSTATUS"){
130             QString status = tpUtility->getAccountStatus();
131             qDebug() << "Account Status is "<< status;
132         }
133         else if (instruction == "--create-account"){
134 #if defined(Q_WS_MAEMO_6)
135             qDebug() << "Creating account";
136             accountUtility->addAccount();
137 #else
138             qDebug() << "This command is applicable only in harmattan";
139 #endif
140         }
141         else if (instruction == "--delete-account"){
142 #if defined(Q_WS_MAEMO_6)
143             qDebug() << "Deleting account";
144             accountUtility->removeAccount();
145 #else
146             qDebug() << "This command is applicable only in harmattan";
147 #endif
148         }
149         else if (instruction == "TESTING"){
150             tpUtility->callNumberWithRing(argv[2]);
151         }
152     }
153     else{                        
154
155         qDebug() << "Sending Introspect method call";
156
157         DbusUtility dbusUtility(&app);
158         QList<QVariant> argsToSend;
159
160
161         bool success = dbusUtility.sendMethodCall("org.freedesktop.Telepathy.Connection.ring.tel.ring",
162                                    "/org/freedesktop/Telepathy/Connection/ring/tel/ring",
163                                    "org.freedesktop.DBus.Introspectable",
164                                    "Introspect",argsToSend,false);
165
166         success = dbusUtility.sendMethodCall("org.freedesktop.Telepathy.ConnectionManager.ring",
167                                    "/org/freedesktop/Telepathy/ConnectionManager/ring",
168                                    "org.freedesktop.DBus.Introspectable",
169                                    "Introspect",argsToSend,false);
170
171         /*
172
173         bool success = dbusUtility.sendMethodCall("org.freedesktop.Telepathy.AccountManager",
174                                    "/org/freedesktop/Telepathy/Account/ring/tel/ring",
175                                    "org.freedesktop.Telepathy.Account",
176                                    "Reconnect",argsToSend,false);
177         */
178
179         if (!success){
180             qDebug() << dbusUtility.getErrorMessage();
181         }
182         else{
183             qDebug() << "Method call executed successfully";
184         }
185         app.exec();
186     }
187 >>>>>>> 74800375ecf7f41e290cf7cc7fa9ee8b230be68e
188
189         qDebug() << QCryptographicHash::hash("VICaR",QCryptographicHash::Md5).toHex();
190
191     }
192     delete (tpUtility);
193     delete (databaseUtility);
194     delete (accountUtility);
195     tpUtility = 0;
196     databaseUtility = 0;
197     accountUtility = 0;
198 }