Release version 0.7-0
[vicar] / src / vicar-utils / cpp / main.cpp
1 /*
2 @version: 0.7
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;
49     DatabaseUtility databaseUtility;
50
51     if (argc > 1 && argv[1]){
52         QString instruction = QString(argv[1]);
53         if (instruction == "INSTALL"){
54             //Check if Account already exists                                                            
55             if (!tpUtility.accountExists()){
56                 qDebug() << "VICaR account not found. Creating ..";
57                 bool result = tpUtility.createAccount();
58                 if (!result) exit(1);
59             }
60             else{
61                 qDebug() << "VICaR account found.";
62             }
63         }
64         else if (instruction == "REMOVE"){
65             bool result = tpUtility.deleteAccount();
66             if (!result) exit(2);
67         }
68         else if (instruction == "TESTING"){
69             tpUtility.callNumberWithRing(argv[2]);
70         }
71         else if (instruction == "TPACCOUNTSTATUS"){
72             QString status = tpUtility.getAccountStatus();
73             qDebug() << "Account Status is "<< status;
74         }
75 #if defined(Q_WS_MAEMO_5)
76         else if (instruction == "CREATEDB"){
77             bool result = databaseUtility.openDatabase();
78             if (!result){
79                 qDebug() <<"Error creating vicar database. "
80                         <<databaseUtility.lastError();
81                 exit(3);
82             }
83
84             qDebug() << "VICaR database opened.";
85             qDebug() << "Preparing VICaR tables..";
86             result = databaseUtility.prepareTables();
87             if (!result){
88                 qDebug() <<"Error creating tables. "
89                         <<databaseUtility.lastError();
90                 exit(4);
91             }
92
93             databaseUtility.closeDatabase();
94         }
95         else if (instruction == "DROPDB"){
96             bool result = databaseUtility.deleteDatabase();
97             if (!result){
98                 qDebug() <<"Error deleting vicar database. "
99                         <<databaseUtility.lastError();
100                 exit(5);
101             }
102             qDebug() << "VICaR database deleted.";
103         }    
104 #elif defined(Q_WS_MAEMO_6)
105         else if (instruction == "--create-account"){
106             qDebug() << "Creating account";
107             HarmattanAccountUtility accountUtility;
108             accountUtility.addAccount();
109         }
110         else if (instruction == "--delete-account"){
111             qDebug() << "Deleting account";
112             HarmattanAccountUtility accountUtility;
113             accountUtility.removeAccount();
114         }
115 #endif
116         else {
117             qDebug() << "This command is not recognized";
118         }
119     }
120     else{                        
121
122         qDebug() << QCryptographicHash::hash("VICaR",QCryptographicHash::Md5).toHex();
123
124     }
125 }