Adding new postinst
[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>
14 #include "dbusutility.h"
15 #include <QDBusMetaType>
16 #include <QDBusConnection>
17 #include <QCryptographicHash> //DEBUG
18
19
20 #include <QDBusInterface>
21 #include <QDBusObjectPath>
22 #include <QDBusArgument>
23
24 #define AM_SERVICE          "org.freedesktop.Telepathy.AccountManager"
25 #define AM_OBJ_PATH         "/org/freedesktop/Telepathy/AccountManager"
26 #define AM_INTERFACE        "org.freedesktop.Telepathy.AccountManager"
27 #define RING_CONN_SERVICE   "org.freedesktop.Telepathy.Connection.ring.tel.ring"
28 #define RING_CONN_PATH      "/org/freedesktop/Telepathy/Connection/ring/tel/ring"
29 #define DBUS_SERVICE        "org.freedesktop.DBus.Properties"
30 #define DBUS_OBJ_PATH       "/org/freedesktop/DBus/Properties"
31 #define DBUS_PROPS_IFACE     "org.freedesktop.DBus.Properties"
32
33 int main(int argc, char *argv[])
34 {
35
36     QCoreApplication app(argc,argv);
37
38     qDBusRegisterMetaType<org::freedesktop::Telepathy::SimplePresence>();
39     //From Connection Interface Requests
40     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetails>();
41     qDBusRegisterMetaType<org::freedesktop::Telepathy::ChannelDetailsList>();
42     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClass>();
43     qDBusRegisterMetaType<org::freedesktop::Telepathy::RequestableChannelClassList>();
44     //From Vicar Profile Types
45     //qDBusRegisterMetaType<org::maemo::vicar::Profile>();
46     //qDBusRegisterMetaType<org::maemo::vicar::ProfileList>();
47
48     TelepathyUtility *tpUtility = new TelepathyUtility();
49     DatabaseUtility *databaseUtility = new DatabaseUtility();
50     HarmattanAccountUtility *accountUtility = new HarmattanAccountUtility();
51
52     if (argc > 1 && argv[1]){
53         QString instruction = QString(argv[1]);
54         if (instruction == "INSTALL"){
55             //Check if Account already exists                                                            
56             if (!tpUtility->accountExists()){
57                 qDebug() << "VICaR account not found. Creating ..";
58                 bool result = tpUtility->createAccount();
59                 if (!result) exit(1);
60             }
61             else{
62                 qDebug() << "VICaR account found.";
63             }
64         }
65         else if (instruction == "REMOVE"){
66             bool result = tpUtility->deleteAccount();
67             if (!result) exit(2);
68         }
69         else if (instruction == "TESTING"){
70             tpUtility->callNumberWithRing(argv[2]);
71         }
72         else if (instruction == "TPACCOUNTSTATUS"){
73             QString status = tpUtility->getAccountStatus();
74             qDebug() << "Account Status is "<< status;
75         }
76 #if defined(Q_WS_MAEMO_5)
77         else if (instruction == "CREATEDB"){
78             bool result = databaseUtility->openDatabase();
79             if (!result){
80                 qDebug() <<"Error creating vicar database. "
81                         <<databaseUtility->lastError();
82                 exit(3);
83             }
84
85             qDebug() << "VICaR database opened.";
86             qDebug() << "Preparing VICaR tables..";
87             result = databaseUtility->prepareTables();
88             if (!result){
89                 qDebug() <<"Error creating tables. "
90                         <<databaseUtility->lastError();
91                 exit(4);
92             }
93
94             databaseUtility->closeDatabase();
95         }
96         else if (instruction == "DROPDB"){
97             bool result = databaseUtility->deleteDatabase();
98             if (!result){
99                 qDebug() <<"Error deleting vicar database. "
100                         <<databaseUtility->lastError();
101                 exit(5);
102             }
103             qDebug() << "VICaR database deleted.";
104         }    
105 #elif defined(Q_WS_MAEMO_6)
106         else if (instruction == "--create-account"){
107             qDebug() << "Creating account";
108             accountUtility->addAccount();
109         }
110         else if (instruction == "--delete-account"){
111             qDebug() << "Deleting account";
112             accountUtility->removeAccount();
113         }
114 #endif
115         else {
116             qDebug() << "This command is not recognized";
117         }
118     }
119     else{                        
120
121         qDebug() << QCryptographicHash::hash("VICaR",QCryptographicHash::Md5).toHex();
122
123     }
124     delete (tpUtility);
125     delete (databaseUtility);
126     delete (accountUtility);
127     tpUtility = 0;
128     databaseUtility = 0;
129     accountUtility = 0;
130 }