README
[n9profile] / profiledeamon.cpp
1 #include <libprofile.h> // knihovna pro přípojení k profile deamonu
2 #include <QtCore/QDebug> //Debug pro informace
3 #include "profiledeamon.h"
4 #include "profil.h"
5
6 /** Constructor.
7 Empty.
8 */
9 ProfileDeamon::ProfileDeamon(QObject *parent) :
10         QObject(parent)
11 {
12
13 }
14
15 /** Destruktor.
16 */
17 ProfileDeamon::~ProfileDeamon()
18 {
19     //odpojím se
20     profile_tracker_quit();
21 }
22
23 /** ConnectToDeamon()
24  Connect to profile deamon
25 */
26
27 /**
28   V dbusus je funkce
29 dbus_message_new_signal         (       const char *     path,
30                 const char *    interface,
31                 const char *    name
32         )
33
34 Parameters:
35         path    the path to the object emitting the signal
36         interface       the interface the signal is emitted from
37         name    name of the signal
38
39 v DB na calendar je
40 static const char* CALENDAR_DBUS_LISTENER_SERVICE =  "com.nokia.calendar";
41 static const char* CALENDAR_DBUS_OBJECT_PATH =  "/com/nokia/calendar";
42 static const char* CALENDAR_DBUS_LISTENER_SIGNAL = "dbChange";
43
44     dbusMessage = dbus_message_new_signal(CALENDAR_DBUS_OBJECT_PATH,
45                       CALENDAR_DBUS_LISTENER_SERVICE,
46                       CALENDAR_DBUS_LISTENER_SIGNAL);
47
48
49                       lib profile má
50 #define         PROFILED_SERVICE   "com.nokia.profiled"
51 #define         PROFILED_PATH   "/com/nokia/profiled"
52 #define         PROFILED_INTERFACE   "com.nokia.profiled"
53                       #define   PROFILED_CHANGED   "profile_changed
54
55                       v QT4
56  bool QDBusConnection::connect ( const QString & service, const QString & path, const QString & interface,
57  const QString & name, QObject  * receiver, const char * slot )
58   */
59
60 /** ConnectToDeamon()
61 connect to profiled deamon
62 */
63 bool ProfileDeamon::ConnectToDeamon()
64 {
65     int a = 0;
66     profile_connection_enable_autoconnect(); // nastavím
67
68     if((a = profile_tracker_init()) != 0){
69         //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" <<  "cannot connect to deamon";
70         return false;
71     }
72     //profile_track_add_active_cb(profileTrack, NULL, unlo );
73     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" <<  "connected to deamon";
74     // QDBusConnection con = QDBusConnection::connectToBus(QDBusConnection::SessionBus,QString("muj"));
75
76     //if(con.isConnected())  //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "neeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee pripojen";
77     return true;
78 }
79
80 /** SetProfile( Profil * profil)
81   Set profile
82   \param profil reference to an object with the data profile
83 */
84 bool ProfileDeamon::SetProfile( Profil * profil)
85 {
86
87     //list of all the values in the profile
88     QList<ProfileValue *>* p_profile_values =  profil->ListOfValues();
89     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "nastavuji:";
90     for (int i = 0; i < p_profile_values->size(); ++i) {
91
92         if(p_profile_values->at(i)->type.contains("SOUNDFILE"))//kdyz je proměnná text
93         {
94           //  qDebug() <<  __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ <<  "nastavuji:" << p_profile_values->at(i)->key << "hodnota " << p_profile_values->at(i)->value.toString();
95             if(profile_set_value("general", p_profile_values->at(i)->key.toLatin1().data(),  p_profile_values->at(i)->value.toString().toLatin1().data()) == -1){
96                 return false;
97             }
98         }else  if(p_profile_values->at(i)->type.contains("BOOLEAN"))//kdyz je proměnná bool
99         {
100             //qDebug() <<  __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ <<  "nastavuji:" << p_profile_values->at(i)->key;
101             if(profile_set_value_as_bool("general", p_profile_values->at(i)->key.toLatin1().data(),  p_profile_values->at(i)->value.toBool()) == -1){
102                 return false;
103             }
104         }else if(p_profile_values->at(i)->type.contains("INTEGER"))//kdyz je proměnná int
105         {
106             //qDebug() <<  __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ <<  "nastavuji:" << p_profile_values->at(i)->key;
107             if(profile_set_value_as_int("general", p_profile_values->at(i)->key.toLatin1().data(),  p_profile_values->at(i)->value.toInt()) == -1){
108                 return false;
109             }
110         }else if(p_profile_values->at(i)->type.contains("STRING"))//kdyz je proměnná text
111         {
112             //qDebug() <<  __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ <<  "nastavuji:" << p_profile_values->at(i)->key;
113             if(profile_set_value("general", p_profile_values->at(i)->key.toLatin1().data(),  p_profile_values->at(i)->value.toString().toLatin1().data()) == -1){
114                 return false;
115             }
116         }
117     }
118     return true;
119 }
120
121 /** GetProfile(QString profil_name)
122   Return profile (general a silent)
123   \param profil_name Profile Name
124 */
125 Profil ProfileDeamon::GetProfile(QString profil_name)
126 {
127     Profil profil(profil_name);
128     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "Get profile from deamon";
129     profileval_t* data_profile =  profile_get_values(profil_name.toLatin1().data());
130     for(int i = 0; i < 15; i++)
131     {
132         //qDebug() << i + 1;
133         //qDebug() << "|->>>klic: " << data_profile[i].pv_key ;
134         //qDebug() << "|->>>hodnota: " << data_profile[i].pv_val ;
135         //qDebug() << "|->>>typ: " << data_profile[i].pv_type ;
136         //deamon return bool value on or off
137         if(data_profile[i].pv_type == QString("BOOLEAN")){
138             if(data_profile[i].pv_val == QString("On")){
139                 profil.SetValue(data_profile[i].pv_key, "1");
140             } else {
141                 profil.SetValue(data_profile[i].pv_key, "0");
142             }
143         } else {
144             profil.SetValue(data_profile[i].pv_key, data_profile[i].pv_val);
145         }
146     }
147     //free
148     profile_free_values(data_profile);
149     //qDebug() << "In file:" <<  __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << "return from getprofile";
150     return profil;
151 }