qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
aboutfriendform.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "aboutfriendform.h"
21 #include "src/widget/gui.h"
22 #include "ui_aboutfriendform.h"
23 #include "src/core/core.h"
24 #include "src/widget/style.h"
25 
26 #include <QFileDialog>
27 #include <QMessageBox>
28 
29 AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget* parent)
30  : QDialog(parent)
31  , ui(new Ui::AboutFriendForm)
32  , about{std::move(_about)}
33 {
34  ui->setupUi(this);
35  ui->label_4->hide();
36  ui->aliases->hide();
37 
38  connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AboutFriendForm::onAcceptedClicked);
39  connect(ui->autoacceptfile, &QCheckBox::clicked, this, &AboutFriendForm::onAutoAcceptDirClicked);
40  connect(ui->autoacceptcall, SIGNAL(activated(int)), this, SLOT(onAutoAcceptCallClicked(void)));
41  connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutFriendForm::onAutoGroupInvite);
42  connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutFriendForm::onSelectDirClicked);
43  connect(ui->removeHistory, &QPushButton::clicked, this, &AboutFriendForm::onRemoveHistoryClicked);
44  about->connectTo_autoAcceptDirChanged(this, [=](const QString& dir){ onAutoAcceptDirChanged(dir); });
45 
46  const QString dir = about->getAutoAcceptDir();
47  ui->autoacceptfile->setChecked(!dir.isEmpty());
48 
49  ui->removeHistory->setEnabled(about->isHistoryExistence());
50 
51  const int index = static_cast<int>(about->getAutoAcceptCall());
52  ui->autoacceptcall->setCurrentIndex(index);
53 
54  ui->selectSaveDir->setEnabled(ui->autoacceptfile->isChecked());
55  ui->autogroupinvite->setChecked(about->getAutoGroupInvite());
56 
57  if (ui->autoacceptfile->isChecked()) {
58  ui->selectSaveDir->setText(about->getAutoAcceptDir());
59  }
60 
61  const QString name = about->getName();
62  setWindowTitle(name);
63  ui->userName->setText(name);
64  ui->publicKey->setText(about->getPublicKey().toString());
65  ui->publicKey->setCursorPosition(0); // scroll textline to left
66  ui->note->setPlainText(about->getNote());
67  ui->statusMessage->setText(about->getStatusMessage());
68  ui->avatar->setPixmap(about->getAvatar());
69 
71 
72  reloadTheme();
73 }
74 
75 static QString getAutoAcceptDir(const QString& dir)
76 {
77  //: popup title
78  const QString title = AboutFriendForm::tr("Choose an auto-accept directory");
79  return QFileDialog::getExistingDirectory(Q_NULLPTR, title, dir);
80 }
81 
83 {
84  const QString dir = [&]{
85  if (!ui->autoacceptfile->isChecked()) {
86  return QString{};
87  }
88 
89  return getAutoAcceptDir(about->getAutoAcceptDir());
90  }();
91 
92  about->setAutoAcceptDir(dir);
93 }
94 
96 {
97  setStyleSheet(Style::getStylesheet("window/general.css"));
98 }
99 
101 {
102  const bool enabled = !path.isNull();
103  ui->autoacceptfile->setChecked(enabled);
104  ui->selectSaveDir->setEnabled(enabled);
105  ui->selectSaveDir->setText(enabled ? path : tr("Auto-accept for this contact is disabled"));
106 }
107 
108 
110 {
111  const int index = ui->autoacceptcall->currentIndex();
112  const IFriendSettings::AutoAcceptCallFlags flag{index};
113  about->setAutoAcceptCall(flag);
114 }
115 
120 {
121  about->setAutoGroupInvite(ui->autogroupinvite->isChecked());
122 }
123 
125 {
126  const QString dir = getAutoAcceptDir(about->getAutoAcceptDir());
127  about->setAutoAcceptDir(dir);
128 }
129 
134 {
135  about->setNote(ui->note->toPlainText());
136 }
137 
139 {
140  const bool retYes = GUI::askQuestion(tr("Confirmation"),
141  tr("Are you sure to remove %1 chat history?").arg(about->getName()),
142  /* defaultAns = */ false, /* warning = */ true, /* yesno = */ true);
143  if (!retYes) {
144  return;
145  }
146 
147  const bool result = about->clearHistory();
148 
149  if (!result) {
150  GUI::showWarning(tr("History removed"),
151  tr("Failed to remove chat history with %1!").arg(about->getName()).toHtmlEscaped());
152  return;
153  }
154 
155  emit histroyRemoved();
156 
157  ui->removeHistory->setEnabled(false); // For know clearly to has removed the history
158 }
159 
161 {
162  delete ui;
163 }
style.h
AboutFriendForm::onAutoAcceptCallClicked
void onAutoAcceptCallClicked()
Definition: aboutfriendform.cpp:109
AboutFriendForm::onAutoAcceptDirChanged
void onAutoAcceptDirChanged(const QString &path)
Definition: aboutfriendform.cpp:100
AboutFriendForm::reloadTheme
void reloadTheme()
Definition: aboutfriendform.cpp:95
AboutFriendForm::~AboutFriendForm
~AboutFriendForm()
Definition: aboutfriendform.cpp:160
AboutFriendForm::onAutoAcceptDirClicked
void onAutoAcceptDirClicked()
Definition: aboutfriendform.cpp:82
GUI::askQuestion
static bool askQuestion(const QString &title, const QString &msg, bool defaultAns=false, bool warning=true, bool yesno=true)
Asks the user a question with Ok/Cancel or Yes/No buttons.
Definition: gui.cpp:169
AboutFriendForm::AboutFriendForm
AboutFriendForm(std::unique_ptr< IAboutFriend > about, QWidget *parent=nullptr)
Definition: aboutfriendform.cpp:29
GUI::getInstance
static GUI & getInstance()
Returns the singleton instance.
Definition: gui.cpp:56
Ui
Definition: filetransferwidget.h:30
AboutFriendForm::about
const std::unique_ptr< IAboutFriend > about
Definition: aboutfriendform.h:43
GUI::themeReload
void themeReload()
AboutFriendForm::onAutoGroupInvite
void onAutoGroupInvite()
Sets the AutoGroupinvite status and saves the settings.
Definition: aboutfriendform.cpp:119
AboutFriendForm::onSelectDirClicked
void onSelectDirClicked()
Definition: aboutfriendform.cpp:124
GUI::showWarning
static void showWarning(const QString &title, const QString &msg)
Show a warning to the user.
Definition: gui.cpp:130
Style::getStylesheet
static const QString getStylesheet(const QString &filename, const QFont &baseFont=QFont())
Definition: style.cpp:165
AboutFriendForm::ui
Ui::AboutFriendForm * ui
Definition: aboutfriendform.h:42
AboutFriendForm::onRemoveHistoryClicked
void onRemoveHistoryClicked()
Definition: aboutfriendform.cpp:138
AboutFriendForm::histroyRemoved
void histroyRemoved()
AboutFriendForm
Definition: aboutfriendform.h:33
core.h
AboutFriendForm::onAcceptedClicked
void onAcceptedClicked()
Called when user clicks the bottom OK button, save all settings.
Definition: aboutfriendform.cpp:133
aboutfriendform.h
gui.h