diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-10-27 13:56:40 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2013-10-27 13:56:40 +0000 |
| commit | b20fa0dc167959d3738628d902799009120893b8 (patch) | |
| tree | 54107eb8c93c095d4d7b0dd10e113307fa08d25e /pica-client | |
| parent | 7d18e6fc53b400e618aeba9181188e934e23cbe1 (diff) | |
| download | pica-pica-b20fa0dc167959d3738628d902799009120893b8.tar.gz pica-pica-b20fa0dc167959d3738628d902799009120893b8.zip | |
ask if user wants to add new peer to contact list
git-svn-id: svn://localhost/project_picapica/trunk@295 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'pica-client')
| -rw-r--r-- | pica-client/chatwindow.cpp | 115 | ||||
| -rw-r--r-- | pica-client/chatwindow.h | 12 |
2 files changed, 104 insertions, 23 deletions
diff --git a/pica-client/chatwindow.cpp b/pica-client/chatwindow.cpp index ef34823..a746561 100644 --- a/pica-client/chatwindow.cpp +++ b/pica-client/chatwindow.cpp @@ -10,12 +10,47 @@ #include <QDateTime> #include <QMessageBox> + ChatWindow::ChatWindow(QByteArray peer_id) : QWidget(0), peer_id_(peer_id), hist(config_dbname, Accounts::GetCurrentAccount().id) { QVBoxLayout *layout; QString title; + + + { + Contacts ct(config_dbname, Accounts::GetCurrentAccount().id); + peer_name_ = ct.GetContactName(peer_id_); + + title = peer_name_; + + if (peer_name_.isEmpty()) + peer_name_ = peer_id_.toBase64(); + + QList<Contacts::ContactRecord> L = ct.GetContacts(Contacts::temporary); + addcontactquestion = false; + for (int i = 0; i < L.size(); i++) + { + if (L[i].id == peer_id_) + { + addcontactquestion = true; + break; + } + } + + } + { + Accounts ac(config_dbname); + my_name_ = ac.GetName(Accounts::GetCurrentAccount().id); + + if (my_name_.isEmpty()) + my_name_ = Accounts::GetCurrentAccount().id.toBase64(); + } + + title = QObject::tr("Chat with ") + title + " - " + peer_id_.toBase64(); + setWindowTitle(title); + layout = new QVBoxLayout; chatw = new QTextEdit(this); @@ -32,6 +67,28 @@ ChatWindow::ChatWindow(QByteArray peer_id) : layout->addWidget(chatw, 3); layout->addWidget(sendtextw, 1, Qt::AlignBottom); + if (addcontactquestion) + { + QHBoxLayout *hl = new QHBoxLayout(); + + lbAddCtQuestion = new QLabel(tr("Do you want to add \"%1\" to your contact list?").arg(peer_name_)); + btAddCtYes = new QPushButton(tr("Yes")); + btAddCtNo = new QPushButton(tr("No")); + btAddCtBlacklist = new QPushButton(tr("Add to blacklist")); + + layout->insertWidget(2, lbAddCtQuestion, Qt::AlignLeft); + + hl->addWidget(btAddCtYes); + hl->addWidget(btAddCtNo); + hl->addWidget(btAddCtBlacklist); + + layout->insertLayout(3, hl); + + connect(btAddCtYes, SIGNAL(clicked()), this, SLOT(addct_yes())); + connect(btAddCtNo, SIGNAL(clicked()), this, SLOT(addct_no())); + connect(btAddCtBlacklist, SIGNAL(clicked()), this, SLOT(addct_blacklist())); + } + setLayout(layout); setWindowIcon(picapica_ico_sit); @@ -44,10 +101,6 @@ ChatWindow::ChatWindow(QByteArray peer_id) : hist1week = new QAction(tr("Last &Week"), this); histAll = new QAction(tr("&All"), this); - connect(hist24h, SIGNAL(triggered()), this, SLOT(show_history24h())); - connect(hist1week, SIGNAL(triggered()), this, SLOT(show_history1w())); - connect(histAll,SIGNAL(triggered()), this, SLOT(show_historyAll())); - { QMenu *m; m = menu->addMenu(tr("&History")); @@ -56,28 +109,12 @@ ChatWindow::ChatWindow(QByteArray peer_id) : m->addAction(hist1week); m->addAction(histAll); } - layout->insertSpacing(0, menu->size().height()); - { - Contacts ct(config_dbname, Accounts::GetCurrentAccount().id); - peer_name_ = ct.GetContactName(peer_id_); - - title = peer_name_; - - if (peer_name_.isEmpty()) - peer_name_ = peer_id_.toBase64(); - - } - { - Accounts ac(config_dbname); - my_name_ = ac.GetName(Accounts::GetCurrentAccount().id); + connect(hist24h, SIGNAL(triggered()), this, SLOT(show_history24h())); + connect(hist1week, SIGNAL(triggered()), this, SLOT(show_history1w())); + connect(histAll,SIGNAL(triggered()), this, SLOT(show_historyAll())); - if (my_name_.isEmpty()) - my_name_ = Accounts::GetCurrentAccount().id.toBase64(); - } - title = QObject::tr("Chat with ") + title + " - " + peer_id_.toBase64(); - setWindowTitle(title); } void ChatWindow::put_message(QString msg, QByteArray id, bool is_me) @@ -269,3 +306,35 @@ void ChatWindow::show_historyAll() print_history(hist.GetMessages(peer_id_, 0, QDateTime::currentDateTime().toTime_t())); } +void ChatWindow::addct_yes() +{ + Contacts ct(config_dbname, Accounts::GetCurrentAccount().id); + + ct.Add(peer_id_, Contacts::regular); + addct_removequestion(); +} + +void ChatWindow::addct_no() +{ + addct_removequestion(); +} + +void ChatWindow::addct_blacklist() +{ + Contacts ct(config_dbname, Accounts::GetCurrentAccount().id); + + ct.Add(peer_id_, Contacts::blacklisted); + addct_removequestion(); +} + +void ChatWindow::addct_removequestion() +{ + if (addcontactquestion) + { + delete btAddCtYes; + delete btAddCtNo; + delete btAddCtBlacklist; + delete lbAddCtQuestion; + addcontactquestion = false; + } +} diff --git a/pica-client/chatwindow.h b/pica-client/chatwindow.h index 0be8ea0..0f4002e 100644 --- a/pica-client/chatwindow.h +++ b/pica-client/chatwindow.h @@ -7,6 +7,8 @@ #include <QMenuBar> #include <QAction> #include <QMenu> +#include <QPushButton> +#include <QLabel> #include "history.h" class TextSend : public QTextEdit @@ -51,6 +53,11 @@ private: QAction *histAll; QString peer_name_; QString my_name_; + bool addcontactquestion; + QPushButton *btAddCtYes; + QPushButton *btAddCtNo; + QPushButton *btAddCtBlacklist; + QLabel *lbAddCtQuestion; void put_message(QString msg, QByteArray id, bool is_me); int draw_message(QString msg, QString nickname, QString datetime, QString color, bool is_delivered); @@ -64,6 +71,11 @@ private slots: void show_history24h(); void show_history1w(); void show_historyAll(); + + void addct_yes(); + void addct_no(); + void addct_blacklist(); + void addct_removequestion(); }; #endif // CHATWINDOW_H |
