a5a19da01012ccc93f498a104c937be4a109d8f3
[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 #include <QCoreApplication> //DEBUG - Delete this
14 #include "dbusutility.h"
15 #include <QDBusMetaType>
16 #include <QDBusConnection>
17
18 int main(int argc, char *argv[])
19 {
20
21     QCoreApplication app(argc,argv);
22
23     qDBusRegisterMetaType<org::freedesktop::Telepathy::SimplePresence>();
24     //From Connection Interface Requests
25     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetails>();
26     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetailsList>();
27     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClass>();
28     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClassList>();
29     //From Vicar Profile Types
30     //qDBusRegisterMetaType<org::maemo::vicar::Profile>();
31     //qDBusRegisterMetaType<org::maemo::vicar::ProfileList>();
32
33     TelepathyUtility *tpUtility = new TelepathyUtility();
34     DatabaseUtility *databaseUtility = new DatabaseUtility();
35     HarmattanAccountUtility *accountUtility = new HarmattanAccountUtility();
36
37     if (argc > 1 && argv[1]){
38         QString instruction = QString(argv[1]);
39         if (instruction == "INSTALL"){
40             //Check if Account already exists
41             if (!tpUtility->accountExists()){
42                 qDebug() << "VICaR account not found. Creating ..";
43                 bool result = tpUtility->createAccount();
44                 if (!result) exit(1);
45             }
46             else{
47                 qDebug() << "VICaR account found.";
48             }
49         }
50         else if (instruction == "REMOVE"){
51             bool result = tpUtility->deleteAccount();
52             if (!result) exit(2);
53         }
54
55         else if (instruction == "CREATEDB"){
56             bool result = databaseUtility->openDatabase();
57             if (!result){
58                 qDebug() <<"Error creating profiles database. "
59                         <<databaseUtility->lastError();
60                 exit(3);
61             }
62             qDebug() << "VICaR profiles database opened.";
63
64             if (!databaseUtility->tableExists("profiles")){
65                 qDebug() << "Creating VICaR profiles table..";
66                 result = databaseUtility->createProfilesTable();
67                 if (!result){
68                     qDebug() <<"Error creating profiles table. "
69                             <<databaseUtility->lastError();
70                     exit(4);
71                 }
72             }
73             else{
74                 qDebug()<<"Profiles table exists";
75             }
76             databaseUtility->closeDatabase();
77         }
78         else if (instruction == "DROPDB"){
79             bool result = databaseUtility->deleteDatabase();
80             if (!result){
81                 qDebug() <<"Error deleting profiles database. "
82                         <<databaseUtility->lastError();
83                 exit(5);
84             }
85             qDebug() << "VICaR profiles database deleted.";
86         }
87         else if (instruction == "TPACCOUNTSTATUS"){
88             QString status = tpUtility->getAccountStatus();
89             qDebug() << "Account Status is "<< status;
90         }
91         else if (instruction == "--create-account"){
92 #if defined(Q_WS_MAEMO_6)
93             qDebug() << "Creating account";
94             accountUtility->addAccount();
95 #else
96             qDebug() << "This command is applicable only in harmattan";
97 #endif
98         }
99         else if (instruction == "--delete-account"){
100 #if defined(Q_WS_MAEMO_6)
101             qDebug() << "Deleting account";
102             accountUtility->removeAccount();
103 #else
104             qDebug() << "This command is applicable only in harmattan";
105 #endif
106         }
107         else if (instruction == "TESTING"){
108             tpUtility->callNumberWithRing(argv[2]);
109         }
110     }
111     else{                        
112
113         qDebug() << "Sending Introspect method call";
114
115         DbusUtility dbusUtility(&app);
116         QList<QVariant> argsToSend;
117
118
119         bool success = dbusUtility.sendMethodCall("org.freedesktop.Telepathy.Connection.ring.tel.ring",
120                                    "/org/freedesktop/Telepathy/Connection/ring/tel/ring",
121                                    "org.freedesktop.DBus.Introspectable",
122                                    "Introspect",argsToSend,false);
123
124         success = dbusUtility.sendMethodCall("org.freedesktop.Telepathy.ConnectionManager.ring",
125                                    "/org/freedesktop/Telepathy/ConnectionManager/ring",
126                                    "org.freedesktop.DBus.Introspectable",
127                                    "Introspect",argsToSend,false);
128
129         /*
130
131         bool success = dbusUtility.sendMethodCall("org.freedesktop.Telepathy.AccountManager",
132                                    "/org/freedesktop/Telepathy/Account/ring/tel/ring",
133                                    "org.freedesktop.Telepathy.Account",
134                                    "Reconnect",argsToSend,false);
135         */
136
137         if (!success){
138             qDebug() << dbusUtility.getErrorMessage();
139         }
140         else{
141             qDebug() << "Method call executed successfully";
142         }
143         app.exec();
144     }
145
146     delete (tpUtility);
147     delete (databaseUtility);
148     delete (accountUtility);
149     tpUtility = 0;
150     databaseUtility = 0;
151     accountUtility = 0;
152 }