diff --git a/projectfiles/QtCreator/TOX-Qt-GUI.pro b/projectfiles/QtCreator/TOX-Qt-GUI.pro
index aa935cc..016521a 100644
--- a/projectfiles/QtCreator/TOX-Qt-GUI.pro
+++ b/projectfiles/QtCreator/TOX-Qt-GUI.pro
@@ -66,7 +66,6 @@ SOURCES += \
../../src/ouruseritemwidget.cpp \
../../src/renameeditwidget.cpp \
../../src/status.cpp \
- ../../src/friendrequestdialog.cpp \
../../src/customhinttextedit.cpp \
../../src/elidelabel.cpp \
../../src/core.cpp \
@@ -88,7 +87,8 @@ SOURCES += \
../../src/customhintwidget.cpp \
../../src/Settings/guisettingspage.cpp \
../../src/frienditemdelegate.cpp \
- ../../src/elidelabeleditable.cpp
+ ../../src/elidelabeleditable.cpp \
+ ../../src/friendrequestwidget.cpp
HEADERS += \
../../src/mainwindow.hpp \
@@ -104,7 +104,6 @@ HEADERS += \
../../src/frienditemwidget.hpp \
../../src/ouruseritemwidget.hpp \
../../src/renameeditwidget.hpp \
- ../../src/friendrequestdialog.hpp \
../../src/customhinttextedit.hpp \
../../src/elidelabel.hpp \
../../src/core.hpp \
@@ -127,7 +126,9 @@ HEADERS += \
../../src/customhintwidget.hpp \
../../src/Settings/guisettingspage.hpp \
../../src/frienditemdelegate.hpp \
- ../../src/elidelabeleditable.hpp
+ ../../src/elidelabeleditable.hpp \
+ ../../src/Settings/guisettingspage.h \
+ ../../src/friendrequestwidget.h
SOURCES += \
../../submodules/ProjectTox-Core/toxcore/DHT.c \
diff --git a/resources/icons/accept.png b/resources/icons/accept.png
new file mode 100644
index 0000000..719e391
Binary files /dev/null and b/resources/icons/accept.png differ
diff --git a/resources/icons/cancel.png b/resources/icons/cancel.png
new file mode 100644
index 0000000..33c876b
Binary files /dev/null and b/resources/icons/cancel.png differ
diff --git a/resources/icons/resultset_next.png b/resources/icons/resultset_next.png
new file mode 100644
index 0000000..59b58a4
Binary files /dev/null and b/resources/icons/resultset_next.png differ
diff --git a/resources/resources.qrc b/resources/resources.qrc
index df0e0be..7abf276 100644
--- a/resources/resources.qrc
+++ b/resources/resources.qrc
@@ -35,5 +35,8 @@
icons/paste_plain.png
icons/arrow_redo.png
icons/arrow_undo.png
+ icons/accept.png
+ icons/cancel.png
+ icons/resultset_next.png
diff --git a/src/friendrequestdialog.cpp b/src/friendrequestdialog.cpp
deleted file mode 100644
index 4836824..0000000
--- a/src/friendrequestdialog.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- Copyright (C) 2013 by Maxim Biro
-
- This file is part of Tox Qt GUI.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- See the COPYING file for more details.
-*/
-
-#include "friendrequestdialog.hpp"
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-FriendRequestDialog::FriendRequestDialog(QWidget *parent, const QString &userId, const QString &message) :
- QDialog(parent)
-{
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
- setWindowTitle("Friend request");
-
- QLabel *friendsLabel = new QLabel("Someone wants to make friends with you.", this);
- QLabel *userIdLabel = new QLabel("User ID:", this);
- QLineEdit *userIdEdit = new QLineEdit(userId, this);
- userIdEdit->setCursorPosition(0);
- userIdEdit->setReadOnly(true);
- QLabel *messageLabel = new QLabel("Friend request message:", this);
- QPlainTextEdit *messageEdit = new QPlainTextEdit(message, this);
- messageEdit->setReadOnly(true);
-
-
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal, this);
-
- buttonBox->addButton("Accept", QDialogButtonBox::AcceptRole);
- buttonBox->addButton("Reject", QDialogButtonBox::RejectRole);
-
- connect(buttonBox, &QDialogButtonBox::accepted, this, &FriendRequestDialog::accept);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &FriendRequestDialog::reject);
-
- QVBoxLayout *layout = new QVBoxLayout(this);
-
- layout->addWidget(friendsLabel);
- layout->addSpacing(12);
- layout->addWidget(userIdLabel);
- layout->addWidget(userIdEdit);
- layout->addWidget(messageLabel);
- layout->addWidget(messageEdit);
- layout->addWidget(buttonBox);
-
- resize(300, 200);
-}
diff --git a/src/friendrequestdialog.hpp b/src/friendrequestdialog.hpp
deleted file mode 100644
index dc6640c..0000000
--- a/src/friendrequestdialog.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- Copyright (C) 2013 by Maxim Biro
-
- This file is part of Tox Qt GUI.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- See the COPYING file for more details.
-*/
-
-#ifndef FRIENDREQUESTDIALOG_HPP
-#define FRIENDREQUESTDIALOG_HPP
-
-#include
-
-class FriendRequestDialog : public QDialog
-{
- Q_OBJECT
-public:
- explicit FriendRequestDialog(QWidget *parent, const QString &userId, const QString &message);
-
-};
-
-#endif // FRIENDREQUESTDIALOG_HPP
diff --git a/src/friendrequestwidget.cpp b/src/friendrequestwidget.cpp
new file mode 100644
index 0000000..d74bba2
--- /dev/null
+++ b/src/friendrequestwidget.cpp
@@ -0,0 +1,201 @@
+/*
+ Copyright (C) 2013 by Martin Kröll
+
+ This file is part of Tox Qt GUI.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the COPYING file for more details.
+*/
+
+#include "friendrequestwidget.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "elidelabel.hpp"
+#include "Settings/settings.hpp"
+
+FriendRequestWidget::FriendRequestWidget(QWidget *parent) :
+ QWidget(parent),
+ it(requests)
+{
+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+
+ button = new QPushButton(this);
+ button->setCheckable(true);
+ button->setProperty("class", "frqButton"); // for CSS styling
+
+ detailsWidget = new QFrame(this);
+ detailsWidget->setFrameShape(QFrame::StyledPanel);
+ detailsWidget->setProperty("class", "frqDetails"); // for CSS styling
+
+ clientId = new ElideLabel(detailsWidget);
+ clientId->setTextElide(true);
+ clientId->setTextElideMode(Qt::ElideRight);
+ clientId->setFixedWidth(100);
+
+ message = new QLabel(detailsWidget);
+ message->setWordWrap(true);
+
+ acceptButton = new QToolButton(detailsWidget);
+ acceptButton->setIcon(QIcon("://icons/accept.png"));
+ acceptButton->setToolTip(tr("Accept request"));
+ acceptButton->setAutoRaise(true);
+
+ rejectButton = new QToolButton(detailsWidget);
+ rejectButton->setIcon(QIcon("://icons/cancel.png"));
+ rejectButton->setToolTip(tr("Reject request"));
+ rejectButton->setAutoRaise(true);
+
+ nextButton = new QToolButton(detailsWidget);
+ nextButton->setIcon(QIcon("://icons/resultset_next.png"));
+ nextButton->setToolTip(tr("Next request"));
+ nextButton->setAutoRaise(true);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addWidget(acceptButton);
+ buttonLayout->addWidget(rejectButton);
+ buttonLayout->addWidget(nextButton);
+ buttonLayout->setContentsMargins(0,0,0,0);
+
+ QVBoxLayout *detailsLayout = new QVBoxLayout(detailsWidget);
+ detailsLayout->setContentsMargins(2,2,2,2);
+ detailsLayout->setSpacing(2);
+ detailsLayout->addWidget(clientId);
+ detailsLayout->addWidget(message);
+ detailsLayout->addLayout(buttonLayout);
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(button);
+ layout->addWidget(detailsWidget);
+ layout->setContentsMargins(4,4,4,4);
+ layout->setSpacing(0);
+
+ connect(button, &QPushButton::toggled, this, &FriendRequestWidget::showDetails);
+ connect(acceptButton, &QPushButton::clicked, this, &FriendRequestWidget::acceptUser);
+ connect(rejectButton, &QPushButton::clicked, this, &FriendRequestWidget::rejectUser);
+ connect(nextButton, &QPushButton::clicked, this, &FriendRequestWidget::nextRequest);
+
+ animation = new QPropertyAnimation(detailsWidget, "maximumHeight");
+ animation->setDuration(200);
+ animation->setLoopCount(1);
+
+ if(Settings::getInstance().isAnimationEnabled()) {
+ detailsWidget->setMaximumHeight(0);
+ } else {
+ detailsWidget->hide();
+ }
+
+ updateGui();
+}
+
+void FriendRequestWidget::addFriendRequest(const QString &userId, const QString &msg)
+{
+ requests.insert(userId, msg);
+ goFirst();
+
+ updateGui();
+}
+
+void FriendRequestWidget::resizeEvent(QResizeEvent *e)
+{
+ QWidget::resizeEvent(e);
+ clientId->setMaximumWidth(detailsWidget->width());
+}
+
+void FriendRequestWidget::acceptUser()
+{
+ emit userAccepted(it.key());
+ it.remove();
+ goFirst();
+
+ updateGui();
+}
+
+void FriendRequestWidget::rejectUser()
+{
+ it.remove();
+ goFirst();
+
+ updateGui();
+}
+
+void FriendRequestWidget::showDetails(bool show)
+{
+ if(show) {
+ goFirst();
+
+ detailsWidget->show();
+ if(Settings::getInstance().isAnimationEnabled()) {
+ animation->setKeyValueAt(0, 0);
+ animation->setKeyValueAt(1, detailsWidget->sizeHint().height());
+ animation->start();
+ } else {
+ detailsWidget->setMaximumHeight(detailsWidget->sizeHint().height());
+ }
+ }
+ else {
+ if(Settings::getInstance().isAnimationEnabled()) {
+ animation->setKeyValueAt(0, detailsWidget->sizeHint().height());
+ animation->setKeyValueAt(1, 0);
+ animation->start();
+ } else {
+ detailsWidget->hide();
+ }
+ }
+}
+
+void FriendRequestWidget::nextRequest()
+{
+ if(it.hasNext()) {
+ it.next();
+ } else {
+ goFirst();
+ }
+ updateGui();
+}
+
+void FriendRequestWidget::updateGui()
+{
+ button->setText(tr("%n friend request(s)","", requests.count()));
+ if(requests.count() > 0) {
+ setVisible(true);
+ clientId->setText(tr("Client ID: %1").arg(it.key()));
+ clientId->setToolTip(it.key());
+ message->setText(QString("\"%1\"").arg(it.value()));
+
+ // Hide next button
+ if(requests.count() == 1) {
+ nextButton->hide();
+ } else {
+ nextButton->show();
+ }
+ }
+ else {
+ button->setChecked(false);
+ setVisible(false);
+ clientId->clear();
+ message->clear();
+ }
+}
+
+/*! Go to first friend request */
+void FriendRequestWidget::goFirst()
+{
+ it.toFront();
+ if(it.hasNext()) {
+ it.next();
+ }
+}
diff --git a/src/friendrequestwidget.h b/src/friendrequestwidget.h
new file mode 100644
index 0000000..ef94462
--- /dev/null
+++ b/src/friendrequestwidget.h
@@ -0,0 +1,78 @@
+/*
+ Copyright (C) 2013 by Martin Kröll
+
+ This file is part of Tox Qt GUI.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ See the COPYING file for more details.
+*/
+
+#ifndef FRIENDREQUESTLABEL_H
+#define FRIENDREQUESTLABEL_H
+
+#include
+
+class QFrame;
+class QLabel;
+class ElideLabel;
+class QPushButton;
+class QToolButton;
+class QPropertyAnimation;
+
+/*! FriendRequestWidget shows incoming friend requests.
+ *
+ * CSS classes for styling
+ * -----------------------
+ *
+ * Object | Qt class | CSS class
+ * ---------------|--------------------|--------------
+ * Button | QPushButton | frqButton
+ * Details widget | QFrame | frqDetails
+ */
+class FriendRequestWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit FriendRequestWidget(QWidget *parent = 0);
+
+signals:
+ void userAccepted(QString);
+
+public slots:
+ void addFriendRequest(const QString &userId, const QString &msg);
+
+protected:
+ void resizeEvent(QResizeEvent *e);
+
+private slots:
+ void acceptUser();
+ void rejectUser();
+ void showDetails(bool show);
+ void nextRequest();
+
+private:
+ QPushButton *button;
+ QFrame *detailsWidget;
+ ElideLabel *clientId;
+ QLabel *message;
+ QToolButton *acceptButton;
+ QToolButton *rejectButton;
+ QToolButton *nextButton;
+
+ QPropertyAnimation *animation;
+
+ QHash requests;
+ QMutableHashIterator it;
+
+ void updateGui();
+ void goFirst();
+};
+
+#endif // FRIENDREQUESTLABEL_H
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 6f8e25b..bdbf88b 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -18,10 +18,10 @@
#include "aboutdialog.hpp"
#include "appinfo.hpp"
-#include "friendrequestdialog.hpp"
#include "pageswidget.hpp"
#include "Settings/settings.hpp"
#include "closeapplicationdialog.hpp"
+#include "friendrequestwidget.h"
#include
#include
@@ -62,6 +62,7 @@ MainWindow::MainWindow(QWidget* parent)
friendDock->setWidget(friendDockWidget);
ourUserItem = new OurUserItemWidget(this);
+ friendRequestWidget = new FriendRequestWidget(this);
friendsWidget = new FriendsWidget(friendDockWidget);
// Create toolbar
@@ -96,6 +97,7 @@ MainWindow::MainWindow(QWidget* parent)
// Create toolbar end
layout->addWidget(ourUserItem);
+ layout->addWidget(friendRequestWidget);
layout->addWidget(friendsWidget);
layout->addWidget(toolBar);
@@ -116,7 +118,7 @@ MainWindow::MainWindow(QWidget* parent)
connect(core, &Core::connected, this, &MainWindow::onConnected);
connect(core, &Core::disconnected, this, &MainWindow::onDisconnected);
- connect(core, &Core::friendRequestRecieved, this, &MainWindow::onFriendRequestRecieved);
+ connect(core, &Core::friendRequestRecieved, friendRequestWidget, &FriendRequestWidget::addFriendRequest);
connect(core, SIGNAL(friendStatusChanged(int, Status)), friendsWidget, SLOT(setStatus(int, Status)));
connect(core, &Core::friendAddressGenerated, ourUserItem, &OurUserItemWidget::setFriendAddress);
connect(core, &Core::friendAdded, friendsWidget, &FriendsWidget::addFriend);
@@ -133,7 +135,7 @@ MainWindow::MainWindow(QWidget* parent)
coreThread->start(/*QThread::IdlePriority*/);
- connect(this, &MainWindow::friendRequestAccepted, core, &Core::acceptFriendRequest);
+ connect(friendRequestWidget, &FriendRequestWidget::userAccepted, core, &Core::acceptFriendRequest);
connect(ourUserItem, &OurUserItemWidget::usernameChanged, core, &Core::setUsername);
connect(core, &Core::usernameSet, ourUserItem, &OurUserItemWidget::setUsername);
@@ -167,15 +169,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
QMainWindow::closeEvent(event);
}
-void MainWindow::onFriendRequestRecieved(const QString& userId, const QString& message)
-{
- FriendRequestDialog dialog(this, userId, message);
-
- if (dialog.exec() == QDialog::Accepted) {
- emit friendRequestAccepted(userId);
- }
-}
-
void MainWindow::onConnected()
{
ourUserItem->setStatus(Status::Online);
diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp
index f5b2dc4..a950dc1 100644
--- a/src/mainwindow.hpp
+++ b/src/mainwindow.hpp
@@ -27,6 +27,8 @@
#include
#include
+class FriendRequestWidget;
+
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -43,11 +45,11 @@ class MainWindow : public QMainWindow
QThread* coreThread;
FriendsWidget* friendsWidget;
OurUserItemWidget* ourUserItem;
+ FriendRequestWidget* friendRequestWidget;
private slots:
void onConnected();
void onDisconnected();
- void onFriendRequestRecieved(const QString &userId, const QString &message);
void onFailedToRemoveFriend(int friendId);
void onFailedToAddFriend(const QString& userId);
void onSettingsActionTriggered();