bc2f3abe710fa8c54d3c93d7bfd3aa43098e6a6f
[vicar] / src / vicar-utils / src / main.cpp
1 /*
2 @version: 0.5
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 <QDebug>
12 #include <QDBusMetaType>
13
14 int main(int argc, char *argv[])
15 {
16     qDBusRegisterMetaType<org::freedesktop::Telepathy::SimplePresence>();
17     //From Connection Interface Requests
18     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetails>();
19     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetailsList>();
20     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClass>();
21     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClassList>();
22     //From Vicar Profile Types
23     //qDBusRegisterMetaType<org::maemo::vicar::Profile>();
24     //qDBusRegisterMetaType<org::maemo::vicar::ProfileList>();
25
26     TelepathyUtility *tpUtility = new TelepathyUtility();
27     DatabaseUtility *databaseUtility = new DatabaseUtility();
28
29     if (argc > 1 && argv[1]){
30         QString instruction = QString(argv[1]);
31         if (instruction == "INSTALL"){
32             //Check if Account already exists
33             if (!tpUtility->accountExists()){
34                 qDebug() << "VICaR account not found. Creating ..";
35                 bool result = tpUtility->createAccount();
36                 if (!result) exit(1);
37             }
38             else{
39                 qDebug() << "VICaR account found.";
40             }
41         }
42         else if (instruction == "REMOVE"){
43             bool result = tpUtility->deleteAccount();
44             if (!result) exit(2);
45         }
46
47         else if (instruction == "CREATEDB"){
48             bool result = databaseUtility->openDatabase();
49             if (!result){
50                 qDebug() <<"Error creating profiles database. "
51                         <<databaseUtility->lastError();
52                 exit(3);
53             }
54             qDebug() << "VICaR profiles database opened.";
55
56             if (!databaseUtility->tableExists("profiles")){
57                 qDebug() << "Creating VICaR profiles table..";
58                 result = databaseUtility->createProfilesTable();
59                 if (!result){
60                     qDebug() <<"Error creating profiles table. "
61                             <<databaseUtility->lastError();
62                     exit(4);
63                 }
64             }
65             else{
66                 qDebug()<<"Profiles table exists";
67             }
68             databaseUtility->closeDatabase();
69         }
70         else if (instruction == "DROPDB"){
71             bool result = databaseUtility->deleteDatabase();
72             if (!result){
73                 qDebug() <<"Error deleting profiles database. "
74                         <<databaseUtility->lastError();
75                 exit(5);
76             }
77             qDebug() << "VICaR profiles database deleted.";
78         }
79         else if (instruction == "ACCOUNTSTATUS"){
80             QString status = tpUtility->getAccountStatus();
81             qDebug() << "Account Status is "<< status;
82         }
83         else if (instruction == "TESTING"){
84             tpUtility->callNumberWithRing(argv[2]);
85         }
86     }
87
88     delete (tpUtility);
89     delete (databaseUtility);
90     tpUtility = 0;
91     databaseUtility = 0;
92 }