summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2013-09-01 12:34:15 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2013-09-01 12:34:15 +0000
commitfe7749bee62380dac4d5dea00b2f5b20db344cbb (patch)
treee46ee11712b0444eee5874328567c050f6498d0b
parentd970ad6a4ac7e077390d8fdac0a4fc576b24dc5c (diff)
downloadpica-pica-fe7749bee62380dac4d5dea00b2f5b20db344cbb.tar.gz
pica-pica-fe7749bee62380dac4d5dea00b2f5b20db344cbb.zip
global variable account_id is replaced with static members Accounts::AccountRecord & Accounts::GetCurrentAccount() and SetCurrentAccount()
git-svn-id: svn://localhost/project_picapica/trunk@268 fb96df88-216d-11de-830c-f3023f12d8ac
-rw-r--r--pica-client/accounts.cpp12
-rw-r--r--pica-client/accounts.h6
-rw-r--r--pica-client/accountswindow.cpp7
-rw-r--r--pica-client/askpassword.cpp5
-rw-r--r--pica-client/chatwindow.cpp10
-rw-r--r--pica-client/contactlistwidget.cpp2
-rw-r--r--pica-client/globals.h1
-rw-r--r--pica-client/main.cpp1
-rw-r--r--pica-client/mainwindow.cpp2
-rw-r--r--pica-client/msguirouter.cpp2
-rw-r--r--pica-client/skynet.cpp4
11 files changed, 35 insertions, 17 deletions
diff --git a/pica-client/accounts.cpp b/pica-client/accounts.cpp
index 4b70b47..a1cfdd0 100644
--- a/pica-client/accounts.cpp
+++ b/pica-client/accounts.cpp
@@ -1,6 +1,18 @@
#include "accounts.h"
#include <QFile>
+Accounts::AccountRecord Accounts::current_account;
+
+Accounts::AccountRecord & Accounts::GetCurrentAccount()
+{
+ return Accounts::current_account;
+}
+
+void Accounts::SetCurrentAccount(Accounts::AccountRecord &rec)
+{
+ Accounts::current_account = rec;
+}
+
Accounts::Accounts(QString storage)
{
dbconn=QSqlDatabase::addDatabase("QSQLITE");
diff --git a/pica-client/accounts.h b/pica-client/accounts.h
index 9389906..8cb6592 100644
--- a/pica-client/accounts.h
+++ b/pica-client/accounts.h
@@ -28,9 +28,15 @@ public:
static bool CheckFiles(AccountRecord& acc, QString &error_string);
+ static AccountRecord &GetCurrentAccount();
+ static void SetCurrentAccount(AccountRecord &rec);
+
private:
+ static AccountRecord current_account;
QSqlDatabase dbconn;
QSqlError lasterr;
+
+
};
#endif // ACCOUNTS_H
diff --git a/pica-client/accountswindow.cpp b/pica-client/accountswindow.cpp
index e8aa781..ea47545 100644
--- a/pica-client/accountswindow.cpp
+++ b/pica-client/accountswindow.cpp
@@ -82,13 +82,11 @@ void AccountsWindow::LoadAccounts()
void AccountsWindow::login_click()
{
-
- memcpy(account_id,(cb_accounts->itemData(cb_accounts->currentIndex())).toByteArray().constData(), PICA_ID_SIZE);
int L_index;
for (int i=0;i<L.count();i++)
{
- if (L[i].id== QByteArray((const char*)account_id, PICA_ID_SIZE))
+ if (L[i].id == cb_accounts->itemData(cb_accounts->currentIndex()))
{
L_index = i;
break;
@@ -105,6 +103,9 @@ void AccountsWindow::login_click()
return;
}
}
+
+ Accounts::SetCurrentAccount(L[L_index]);
+
skynet->Join(L[L_index]);
mainwindow = new MainWindow();
diff --git a/pica-client/askpassword.cpp b/pica-client/askpassword.cpp
index 05c0c83..e3c0696 100644
--- a/pica-client/askpassword.cpp
+++ b/pica-client/askpassword.cpp
@@ -2,6 +2,7 @@
#include "globals.h"
#include <string.h>
#include <QInputDialog>
+#include "accounts.h"
QMutex AskPassword::passwd_mutex;
QMap<QByteArray,QString> AskPassword::idpasswd;
@@ -44,9 +45,9 @@ void AskPassword::password_dialog()
{
bool ok;
QString title = QObject::tr("Enter private key passphrase");
- QString text = QObject::tr(QString("Passphrase for (%1)").arg(QByteArray((const char*)account_id, PICA_ID_SIZE).toBase64().constData()).toUtf8().constData());
+ QString text = QObject::tr(QString("Passphrase for (%1)").arg(Accounts::GetCurrentAccount().id.toBase64().constData()).toUtf8().constData());
QString psw = QInputDialog::getText((QWidget*)mainwindow,title,text,QLineEdit::Password,QString(),&ok);
if (ok)
- idpasswd[QByteArray((const char*)account_id, PICA_ID_SIZE)] = psw;
+ idpasswd[Accounts::GetCurrentAccount().id] = psw;
}
diff --git a/pica-client/chatwindow.cpp b/pica-client/chatwindow.cpp
index 1a7c141..4247bdb 100644
--- a/pica-client/chatwindow.cpp
+++ b/pica-client/chatwindow.cpp
@@ -11,7 +11,7 @@
#include <QMessageBox>
ChatWindow::ChatWindow(QByteArray peer_id) :
- QWidget(0), peer_id_(peer_id), hist(config_dbname, QByteArray((const char*)account_id, PICA_ID_SIZE))
+ QWidget(0), peer_id_(peer_id), hist(config_dbname, Accounts::GetCurrentAccount().id)
{
QVBoxLayout *layout;
@@ -60,7 +60,7 @@ ChatWindow::ChatWindow(QByteArray peer_id) :
layout->insertSpacing(0, menu->size().height());
{
- Contacts ct(config_dbname, QByteArray((const char*)account_id, PICA_ID_SIZE));
+ Contacts ct(config_dbname, Accounts::GetCurrentAccount().id);
peer_name_ = ct.GetContactName(peer_id_);
if (peer_name_.isEmpty())
@@ -69,10 +69,10 @@ ChatWindow::ChatWindow(QByteArray peer_id) :
}
{
Accounts ac(config_dbname);
- my_name_ = ac.GetName(QByteArray((const char*)account_id, PICA_ID_SIZE));
+ my_name_ = ac.GetName(Accounts::GetCurrentAccount().id);
if (my_name_.isEmpty())
- my_name_ = QByteArray((const char*)account_id, PICA_ID_SIZE).toBase64();
+ my_name_ = Accounts::GetCurrentAccount().id.toBase64();
}
}
@@ -210,7 +210,7 @@ void ChatWindow::msg_informational(QString text)
void ChatWindow::send_message()
{
- put_message(sendtextw->toPlainText(), QByteArray((const char*)account_id, PICA_ID_SIZE), true);
+ put_message(sendtextw->toPlainText(), Accounts::GetCurrentAccount().id, true);
hist.Add(peer_id_, sendtextw->toPlainText(), true);
if (!hist.isOK())
diff --git a/pica-client/contactlistwidget.cpp b/pica-client/contactlistwidget.cpp
index 90b10a6..4331b89 100644
--- a/pica-client/contactlistwidget.cpp
+++ b/pica-client/contactlistwidget.cpp
@@ -27,7 +27,7 @@ ContactListWidget::ContactListWidget(QWidget *parent) :
connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(start_chat()));
- setContactsStorage(new Contacts(config_dbname, QByteArray((const char*)account_id, PICA_ID_SIZE)));
+ setContactsStorage(new Contacts(config_dbname, Accounts::GetCurrentAccount().id));
}
ContactListWidget::~ContactListWidget()
diff --git a/pica-client/globals.h b/pica-client/globals.h
index 82eec86..d30305d 100644
--- a/pica-client/globals.h
+++ b/pica-client/globals.h
@@ -18,7 +18,6 @@ extern class QString config_dbname;
extern class QString config_defaultCA;
extern class SkyNet *skynet;
extern class MainWindow *mainwindow;
-extern unsigned char account_id[PICA_ID_SIZE];
extern class AskPassword *askpassword;
extern class MsgUIRouter *msguirouter;
extern class QIcon picapica_ico_sit;
diff --git a/pica-client/main.cpp b/pica-client/main.cpp
index 9dd93fe..55dc10c 100644
--- a/pica-client/main.cpp
+++ b/pica-client/main.cpp
@@ -17,7 +17,6 @@ QString config_dir;
QString config_dbname;
SkyNet *skynet;
MainWindow *mainwindow;
-unsigned char account_id[PICA_ID_SIZE];
class AskPassword *askpassword;
class MsgUIRouter *msguirouter;
diff --git a/pica-client/mainwindow.cpp b/pica-client/mainwindow.cpp
index d6f17c9..1d789e4 100644
--- a/pica-client/mainwindow.cpp
+++ b/pica-client/mainwindow.cpp
@@ -86,7 +86,7 @@ void MainWindow::SetStatus(bool connected)
{
status->setCurrentIndex(0);
setWindowTitle(tr("Pica Pica Messenger - ") +
- QByteArray((const char*)account_id, PICA_ID_SIZE).toBase64().left(8) + "...");
+ Accounts::GetCurrentAccount().id.toBase64().left(8) + "...");
}
else
{
diff --git a/pica-client/msguirouter.cpp b/pica-client/msguirouter.cpp
index d4a62c4..b19bc55 100644
--- a/pica-client/msguirouter.cpp
+++ b/pica-client/msguirouter.cpp
@@ -89,7 +89,7 @@ void MsgUIRouter::delivered(QByteArray to)
}
else
{
- History h(config_dbname, QByteArray((const char*)account_id, PICA_ID_SIZE));
+ History h(config_dbname, Accounts::GetCurrentAccount().id);
h.SetDelivered(to);
}
diff --git a/pica-client/skynet.cpp b/pica-client/skynet.cpp
index 111b79a..974c1a8 100644
--- a/pica-client/skynet.cpp
+++ b/pica-client/skynet.cpp
@@ -65,7 +65,7 @@ void SkyNet::nodethread_connected(QString addr, quint16 port, NodeThread *thread
//load undelivered messages from history
if (msgqueues.isEmpty())
{
- History h(config_dbname, QByteArray((const char*)account_id, PICA_ID_SIZE));
+ History h(config_dbname, Accounts::GetCurrentAccount().id);
msgqueues = h.GetUndeliveredMessages();
}
@@ -100,7 +100,7 @@ void SkyNet::verify_peer_cert(QByteArray peer_id, QString cert_pem, bool *verifi
// ViewCertDialog vcd;
// vcd.SetCert(cert_pem);
// vcd.exec();
- Contacts cnt(config_dbname, QByteArray((const char*)account_id, PICA_ID_SIZE));
+ Contacts cnt(config_dbname, Accounts::GetCurrentAccount().id);
QString stored_cert;
if ((stored_cert = cnt.GetContactCert(peer_id)).isEmpty())