diff --git a/qtox.pro b/qtox.pro index 07fc90490..5d9ed8ad4 100644 --- a/qtox.pro +++ b/qtox.pro @@ -35,7 +35,8 @@ FORMS += \ src/widget/form/settings/avsettings.ui \ src/widget/form/settings/generalsettings.ui \ src/widget/form/settings/privacysettings.ui \ - src/widget/form/removefrienddialog.ui + src/widget/form/removefrienddialog.ui \ + src/widget/about/aboutuser.ui CONFIG += c++11 @@ -507,7 +508,8 @@ SOURCES += \ src/widget/tool/micfeedbackwidget.cpp \ src/widget/tool/removefrienddialog.cpp \ src/video/groupnetcamview.cpp \ - src/core/toxcall.cpp + src/core/toxcall.cpp \ + src/widget/about/aboutuser.cpp HEADERS += \ src/audio/audio.h \ @@ -560,4 +562,5 @@ HEADERS += \ src/video/genericnetcamview.h \ src/video/groupnetcamview.h \ src/core/indexedlist.h \ - src/core/toxcall.h + src/core/toxcall.h \ + src/widget/about/aboutuser.h diff --git a/src/friend.cpp b/src/friend.cpp index 86ba69ab8..8899c4ed7 100644 --- a/src/friend.cpp +++ b/src/friend.cpp @@ -92,10 +92,16 @@ void Friend::setAlias(QString name) void Friend::setStatusMessage(QString message) { + statusMessage = message; widget->setStatusMsg(message); chatForm->setStatusMessage(message); } +QString Friend::getStatusMessage() +{ + return statusMessage; +} + QString Friend::getDisplayedName() const { if (userAlias.size() == 0) diff --git a/src/friend.h b/src/friend.h index 667531235..3d609fde0 100644 --- a/src/friend.h +++ b/src/friend.h @@ -46,6 +46,7 @@ public: bool hasAlias() const; void setStatusMessage(QString message); + QString getStatusMessage(); void setEventFlag(int f); int getEventFlag() const; @@ -64,7 +65,7 @@ signals: void displayedNameChanged(FriendWidget* widget, Status s, int hasNewEvents); private: - QString userAlias, userName; + QString userAlias, userName, statusMessage; ToxId userID; uint32_t friendId; int hasNewEvents; diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 1d626ca47..f7997e7eb 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -304,6 +304,7 @@ void Settings::loadPersonnal(Profile* profile) friendProp fp; fp.addr = ps.value("addr").toString(); fp.alias = ps.value("alias").toString(); + fp.note = ps.value("note").toString(); fp.autoAcceptDir = ps.value("autoAcceptDir").toString(); fp.circleID = ps.value("circle", -1).toInt(); @@ -478,6 +479,7 @@ void Settings::savePersonal(QString profileName, QString password) ps.setArrayIndex(index); ps.setValue("addr", frnd.addr); ps.setValue("alias", frnd.alias); + ps.setValue("note", frnd.note); ps.setValue("autoAcceptDir", frnd.autoAcceptDir); ps.setValue("circle", frnd.circleID); @@ -913,6 +915,34 @@ void Settings::setAutoAcceptDir(const ToxId &id, const QString& dir) } } +QString Settings::getContactNote(const ToxId &id) const +{ + QMutexLocker locker{&bigLock}; + + auto it = friendLst.find(id.publicKey); + if (it != friendLst.end()) + return it->note; + + return QString(); +} + +void Settings::setContactNote(const ToxId &id, const QString& note) +{ + QMutexLocker locker{&bigLock}; + + auto it = friendLst.find(id.publicKey); + if (it != friendLst.end()) + { + qDebug() << note; + it->note = note; + } + else + { + updateFriendAdress(id.toString()); + setContactNote(id, note); + } +} + QString Settings::getGlobalAutoAcceptDir() const { QMutexLocker locker{&bigLock}; @@ -1252,6 +1282,7 @@ void Settings::updateFriendAdress(const QString &newAddr) friendProp fp; fp.addr = newAddr; fp.alias = ""; + fp.note = ""; fp.autoAcceptDir = ""; friendLst[newAddr] = fp; } @@ -1282,6 +1313,7 @@ void Settings::setFriendAlias(const ToxId &id, const QString &alias) friendProp fp; fp.addr = key; fp.alias = alias; + fp.note = ""; fp.autoAcceptDir = ""; friendLst[key] = fp; } @@ -1310,6 +1342,7 @@ void Settings::setFriendCircleID(const ToxId &id, int circleID) friendProp fp; fp.addr = key; fp.alias = ""; + fp.note = ""; fp.autoAcceptDir = ""; fp.circleID = circleID; friendLst[key] = fp; @@ -1339,6 +1372,7 @@ void Settings::setFriendActivity(const ToxId &id, const QDate &activity) friendProp fp; fp.addr = key; fp.alias = ""; + fp.note = ""; fp.autoAcceptDir = ""; fp.circleID = -1; fp.activity = activity; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 73455d9e9..116beaaa8 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -187,8 +187,11 @@ public: int getEmojiFontPointSize() const; void setEmojiFontPointSize(int value); + QString getContactNote(const ToxId& id) const; + void setContactNote(const ToxId& id, const QString& note); + QString getAutoAcceptDir(const ToxId& id) const; - void setAutoAcceptDir(const ToxId&id, const QString& dir); + void setAutoAcceptDir(const ToxId& id, const QString& dir); QString getGlobalAutoAcceptDir() const; void setGlobalAutoAcceptDir(const QString& dir); @@ -394,6 +397,7 @@ private: QString alias; QString addr; QString autoAcceptDir; + QString note; int circleID = -1; QDate activity = QDate(); }; diff --git a/src/widget/about/aboutuser.cpp b/src/widget/about/aboutuser.cpp new file mode 100644 index 000000000..93eb66cbc --- /dev/null +++ b/src/widget/about/aboutuser.cpp @@ -0,0 +1,109 @@ +#include "aboutuser.h" +#include "ui_aboutuser.h" +#include "src/persistence/settings.h" +#include "src/persistence/historykeeper.h" + +#include +#include +#include + +AboutUser::AboutUser(ToxId &toxId, QWidget *parent) : + QDialog(parent), + ui(new Ui::AboutUser) +{ + ui->setupUi(this); + ui->label_4->hide(); + ui->aliases->hide(); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutUser::onAcceptedClicked); + connect(ui->autoaccept, &QCheckBox::clicked, this, &AboutUser::onAutoAcceptClicked); + connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutUser::onSelectDirClicked); + connect(ui->removeHistory, &QPushButton::clicked, this, &AboutUser::onRemoveHistoryClicked); + + this->toxId = toxId; + QString dir = Settings::getInstance().getAutoAcceptDir(this->toxId); + ui->autoaccept->setChecked(!dir.isEmpty()); + ui->selectSaveDir->setEnabled(ui->autoaccept->isChecked()); + + if(ui->autoaccept->isChecked()) + ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->toxId)); +} + +void AboutUser::setFriend(Friend *f) +{ + this->setWindowTitle(f->getDisplayedName()); + ui->userName->setText(f->getDisplayedName()); + ui->publicKey->setText(QString(f->getToxId().toString())); + ui->publicKey->setCursorPosition(0); //scroll textline to left + ui->note->setPlainText(Settings::getInstance().getContactNote(f->getToxId())); + + QPixmap avatar = Settings::getInstance().getSavedAvatar(f->getToxId().toString()); + ui->statusMessage->setText(f->getStatusMessage()); + if(!avatar.isNull()) { + ui->avatar->setPixmap(avatar); + } else { + ui->avatar->setPixmap(QPixmap(":/img/contact_dark.svg")); + } + +} + +void AboutUser::onAutoAcceptClicked() +{ + QString dir; + if (!ui->autoaccept->isChecked()) + { + dir = QDir::homePath(); + ui->autoaccept->setChecked(false); + Settings::getInstance().setAutoAcceptDir(this->toxId, ""); + ui->selectSaveDir->setText(tr("Auto accept for this contact is disabled")); + } + else if (ui->autoaccept->isChecked()) + { + dir = QFileDialog::getExistingDirectory(this, tr("Choose an auto accept directory", + "popup title"), dir); + if(dir.isEmpty()) + { + ui->autoaccept->setChecked(false); + return; // user canellced + } + Settings::getInstance().setAutoAcceptDir(this->toxId, dir); + ui->selectSaveDir->setText(Settings::getInstance().getAutoAcceptDir(this->toxId)); + } + Settings::getInstance().saveGlobal(); + ui->selectSaveDir->setEnabled(ui->autoaccept->isChecked()); +} + +void AboutUser::onSelectDirClicked() +{ + QString dir; + dir = QFileDialog::getExistingDirectory(this, tr("Choose an auto accept directory", + "popup title"), dir); + ui->autoaccept->setChecked(true); + Settings::getInstance().setAutoAcceptDir(this->toxId, dir); + Settings::getInstance().saveGlobal(); +} + +/** + * @brief AboutUser::onAcceptedClicked When users clicks the bottom OK button, + * save all settings + */ +void AboutUser::onAcceptedClicked() +{ + Settings::getInstance().setContactNote(ui->publicKey->text(), ui->note->toPlainText()); + Settings::getInstance().saveGlobal(); +} + +void AboutUser::onRemoveHistoryClicked() +{ + HistoryKeeper::getInstance()->removeFriendHistory(toxId.publicKey); + QMessageBox::StandardButton reply; + reply = QMessageBox::information(this, + tr("History removed"), + tr("Chat history with %1 removed!").arg(ui->userName->text().toHtmlEscaped()), + QMessageBox::Ok); +} + +AboutUser::~AboutUser() +{ + delete ui; +} diff --git a/src/widget/about/aboutuser.h b/src/widget/about/aboutuser.h new file mode 100644 index 000000000..b206b0395 --- /dev/null +++ b/src/widget/about/aboutuser.h @@ -0,0 +1,32 @@ +#ifndef ABOUTUSER_H +#define ABOUTUSER_H + +#include +#include "src/friend.h" + + +namespace Ui { +class AboutUser; +} + +class AboutUser : public QDialog +{ + Q_OBJECT + +public: + explicit AboutUser(ToxId &toxID, QWidget *parent = 0); + ~AboutUser(); + void setFriend(Friend *f); + +private: + Ui::AboutUser *ui; + ToxId toxId; + +private slots: + void onAcceptedClicked(); + void onAutoAcceptClicked(); + void onSelectDirClicked(); + void onRemoveHistoryClicked(); +}; + +#endif // ABOUTUSER_H diff --git a/src/widget/about/aboutuser.ui b/src/widget/about/aboutuser.ui new file mode 100644 index 000000000..d098ac193 --- /dev/null +++ b/src/widget/about/aboutuser.ui @@ -0,0 +1,254 @@ + + + AboutUser + + + + 0 + 0 + 465 + 406 + + + + Dialog + + + + + + + + + + + + username + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + false + + + status message + + + Qt::PlainText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + 0 + 0 + + + + + 75 + 75 + + + + + 75 + 75 + + + + + + + Qt::PlainText + + + ../../../img/contact_dark.svg + + + true + + + + + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + Qt::LeftToRight + + + Public key: + + + + + + + true + + + false + + + false + + + + + + + + + 0 + + + true + + + Qt::LogicalMoveStyle + + + + + + + Used aliases: + + + + + + + HISTORY OF ALIASES + + + Qt::PlainText + + + + + + + Default directory to save files: + + + + + + + Auto accept for this contact is disabled + + + + + + + Auto accept files + + + + + + + + + Remove history (operation can not be undone!) + + + + + + + Notes + + + + + + + + + You can save comment about this contact here. + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AboutUser + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AboutUser + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 8d798546c..59cf07522 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -31,6 +31,7 @@ #include "src/widget/style.h" #include "src/persistence/settings.h" #include "src/widget/widget.h" +#include "src/widget/about/aboutuser.h" #include #include #include @@ -48,8 +49,8 @@ FriendWidget::FriendWidget(int FriendId, QString id) , isDefaultAvatar{true} , historyLoaded{false} { - avatar->setPixmap(QPixmap(":img/contact.svg"), Qt::transparent); - statusPic.setPixmap(QPixmap(":img/status/dot_offline.svg")); + avatar->setPixmap(QPixmap(":/img/contact.svg"), Qt::transparent); + statusPic.setPixmap(QPixmap(":/img/status/dot_offline.svg")); statusPic.setMargin(3); nameLabel->setText(id); nameLabel->setTextFormat(Qt::PlainText); @@ -150,6 +151,9 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) if (contentDialog == nullptr || !contentDialog->hasFriendWidget(friendId, this)) removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist")); + menu.addSeparator(); + QAction* aboutWindow = menu.addAction(tr("Show details")); + QAction* selectedItem = menu.exec(pos); removeEventFilter(this); @@ -188,8 +192,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) autoAccept->setChecked(false); Settings::getInstance().setAutoAcceptDir(id, ""); } - - if (autoAccept->isChecked()) + else if (autoAccept->isChecked()) { dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir); autoAccept->setChecked(true); @@ -197,6 +200,11 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) Settings::getInstance().setAutoAcceptDir(id, dir); } } + else if (selectedItem == aboutWindow) { + AboutUser *aboutUser = new AboutUser(id, Widget::getInstance()); + aboutUser->setFriend(FriendList::findFriend(friendId)); + aboutUser->show(); + } else if (selectedItem == newCircleAction) { if (circleWidget != nullptr) @@ -368,9 +376,9 @@ void FriendWidget::onAvatarRemoved(int FriendId) isDefaultAvatar = true; if (isActive()) - avatar->setPixmap(QPixmap(":img/contact_dark.svg"), Qt::transparent); + avatar->setPixmap(QPixmap(":/img/contact_dark.svg"), Qt::transparent); else - avatar->setPixmap(QPixmap(":img/contact.svg"), Qt::transparent); + avatar->setPixmap(QPixmap(":/img/contact.svg"), Qt::transparent); } void FriendWidget::mousePressEvent(QMouseEvent *ev)