summaryrefslogtreecommitdiffstats
path: root/pica-client/main.cpp
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2012-06-17 21:15:12 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2012-06-17 21:15:12 +0000
commit8df9466ada46e4b07990b9cb7e8b1cd61b96844a (patch)
tree2cb652e5839bed672133ffa90e7ad477f55cfb6b /pica-client/main.cpp
downloadpica-pica-8df9466ada46e4b07990b9cb7e8b1cd61b96844a.tar.gz
pica-pica-8df9466ada46e4b07990b9cb7e8b1cd61b96844a.zip
todo list update
git-svn-id: svn://localhost/project_picapica/trunk@128 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'pica-client/main.cpp')
-rw-r--r--pica-client/main.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/pica-client/main.cpp b/pica-client/main.cpp
new file mode 100644
index 0000000..f7a725b
--- /dev/null
+++ b/pica-client/main.cpp
@@ -0,0 +1,161 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+#include "accountswindow.h"
+#include "globals.h"
+#include "contacts.h"
+#include "skynet.h"
+#include "msguirouter.h"
+#include "picaactioncenter.h"
+#include "picasystray.h"
+#include <QDir>
+#include <QMessageBox>
+#include <QString>
+#include <QIcon>
+
+//globals
+QString config_dir;
+QString config_dbname;
+SkyNet *skynet;
+MainWindow *mainwindow;
+unsigned int account_id;
+class AskPassword *askpassword;
+class MsgUIRouter *msguirouter;
+
+QIcon picapica_ico_sit;
+QIcon picapica_ico_fly;
+
+class PicaActionCenter *action_center;
+class PicaSysTray *systray;
+
+// /usr/share/pica-client/pica-pica_CA.pem
+//QString config_defaultCA("/home/root_jr/files/projects/picapica_wc/localhost/project_picapica/trunk/tests/trusted_CA.pem");
+QString config_defaultCA(PICA_INSTALLPREFIX"share/pica-client/trusted_CA.pem");
+
+static bool create_config_dir()
+{
+ QMessageBox msgBox;
+ config_dir=QDir::homePath()+QDir::separator() +QString(PICA_CLIENT_CONFIGDIR);
+
+ if (!QFile::exists(config_dir))
+ {
+ msgBox.setText(QString("%1 does not exist").arg(config_dir));//debug
+ msgBox.exec();
+
+ QDir dir;
+
+ if (!dir.mkpath(config_dir))
+ {
+ msgBox.setText(QString(QObject::tr("Unable to create configuration directory:\n %1")).arg(config_dir));
+ msgBox.exec();
+ return false;
+ }
+ }
+
+ config_dbname=config_dir+QDir::separator()+QString(PICA_CLIENT_STORAGEDB);
+
+ if (!QFile::exists(config_dbname))
+ {
+ QSqlDatabase dbconn=QSqlDatabase::addDatabase("QSQLITE");
+ dbconn.setDatabaseName(config_dbname);
+
+ if (!dbconn.open())
+ {
+
+ msgBox.setText(dbconn.lastError().text());
+ msgBox.exec();
+ return false;
+ }
+
+ QSqlQuery query;
+
+ query.exec("PRAGMA foreign_keys=ON;");
+
+ if (query.lastError().isValid())
+ goto showerror;
+
+ query.exec("create table accounts \
+ (\
+ id int primary key, \
+ name varchar(64), \
+ cert_file varchar(255) not null, \
+ pkey_file varchar(255) not null, \
+ ca_file varchar(255) default null \
+ );");
+
+ if (query.lastError().isValid())
+ goto showerror;
+
+ query.exec("create table contacts \
+ (\
+ id int,\
+ name varchar(64), \
+ cert_pem text(2048), \
+ account_id int not null, \
+ primary key(id, account_id),\
+ foreign key(account_id) references accounts(id) on delete cascade\
+ );");
+
+ if (query.lastError().isValid())
+ goto showerror;
+
+ query.exec(
+ "create table nodes \
+ (\
+ address varchar(255) not null,\
+ port int not null,\
+ last_active int not null,\
+ inactive_count int not null,\
+ constraint pk primary key (address,port) on conflict replace \
+ );");
+
+
+ if (query.lastError().isValid())
+ showerror:
+ {
+ msgBox.setText(query.lastError().text());
+ msgBox.exec();
+ return false;
+ }
+
+ }
+
+
+ return true;
+
+
+}
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ if (!create_config_dir())
+ return -1;
+
+ picapica_ico_sit = QIcon(PICA_INSTALLPREFIX"share/pica-client/picapica-icon-sit.png");
+ picapica_ico_fly = QIcon(PICA_INSTALLPREFIX"share/pica-client/picapica-icon-fly.png");
+
+ PicaActionCenter ac;
+ action_center = &ac;
+
+ AccountsWindow aw;
+
+ SkyNet s;
+ skynet=&s;
+
+ PicaSysTray pst;
+ systray = &pst;
+
+ AskPassword askpsw;
+ askpassword=&askpsw;
+
+ MsgUIRouter muir;
+ msguirouter = &muir;
+
+
+ aw.show();
+
+ a.setQuitOnLastWindowClosed(false);
+
+ return a.exec();
+}