diff --git a/core.cpp b/core.cpp index 98076fc7d..6cc02e133 100644 --- a/core.cpp +++ b/core.cpp @@ -50,6 +50,7 @@ Core::Core(Camera* cam, QThread *coreThread) : //connect(fileTimer, &QTimer::timeout, this, &Core::fileHeartbeat); connect(bootstrapTimer, &QTimer::timeout, this, &Core::onBootstrapTimer); connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::bootstrapDht); + connect(this, SIGNAL(fileTransferFinished(ToxFile)), this, SLOT(onFileTransferFinished(ToxFile))); for (int i=0; i& newDhtServerList) emit dhtServerListChanged(); } -QString Settings::getUsername() const -{ - return username; -} - -void Settings::setUsername(const QString& newUsername) -{ - username = newUsername; -} - -QString Settings::getStatusMessage() const -{ - return statusMessage; -} - -void Settings::setStatusMessage(const QString& newMessage) -{ - statusMessage = newMessage; -} - bool Settings::getEnableIPv6() const { return enableIPv6; diff --git a/settings.h b/settings.h index 38667ef01..275451f43 100644 --- a/settings.h +++ b/settings.h @@ -43,12 +43,6 @@ public: const QList& getDhtServerList() const; void setDhtServerList(const QList& newDhtServerList); - QString getUsername() const; - void setUsername(const QString& newUsername); - - QString getStatusMessage() const; - void setStatusMessage(const QString& newMessage); - bool getEnableIPv6() const; void setEnableIPv6(bool newValue); @@ -133,9 +127,6 @@ private: int dhtServerId; bool dontShowDhtDialog; - QString username; - QString statusMessage; - bool enableIPv6; bool useTranslations; diff --git a/toxgui.pro b/toxgui.pro index 912a1db59..e39538515 100644 --- a/toxgui.pro +++ b/toxgui.pro @@ -63,6 +63,7 @@ HEADERS += widget/form/addfriendform.h \ widget/form/chatform.h \ widget/form/groupchatform.h \ widget/form/settingsform.h \ + widget/form/filesform.h \ widget/tool/chattextedit.h \ widget/tool/copyableelidelabel.h \ widget/tool/editablelabelwidget.h \ @@ -93,6 +94,7 @@ SOURCES += \ widget/form/chatform.cpp \ widget/form/groupchatform.cpp \ widget/form/settingsform.cpp \ + widget/form/filesform.cpp \ widget/tool/chattextedit.cpp \ widget/tool/copyableelidelabel.cpp \ widget/tool/editablelabelwidget.cpp \ diff --git a/widget/form/filesform.cpp b/widget/form/filesform.cpp new file mode 100644 index 000000000..458af4f1c --- /dev/null +++ b/widget/form/filesform.cpp @@ -0,0 +1,83 @@ +/* + Copyright (C) 2014 by Project Tox + + This file is part of qTox, a Qt-based graphical interface for Tox. + + This program is libre 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 "filesform.h" + +FilesForm::FilesForm() + : QObject() +{ + head = new QWidget(); + QFont bold; + bold.setBold(true); + headLabel.setText(tr("Transfered Files","\"Headline\" of the window")); + headLabel.setFont(bold); + head->setLayout(&headLayout); + headLayout.addWidget(&headLabel); + + main.addTab(&recvd, tr("Downloads")); + main.addTab(&sent, tr("Uploads")); + + connect(&sent, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onUploadFileActivated(QListWidgetItem*))); + connect(&recvd, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onDownloadFileActivated(QListWidgetItem*))); + +} + +FilesForm::~FilesForm() +{ + //delete head; + // having this line caused a SIGABRT because free() received an invalid pointer + // but since this is only called on program shutdown anyways, + // I'm not too bummed about removing it +} + +void FilesForm::show(Ui::Widget& ui) +{ + ui.mainContent->layout()->addWidget(&main); + ui.mainHead->layout()->addWidget(head); + main.show(); + head->show(); +} + +void FilesForm::onFileDownloadComplete(const QString& path) +{ + QListWidgetItem* tmp = new QListWidgetItem(QIcon(":/ui/acceptFileButton/default.png"), path); + recvd.addItem(tmp); +} + +void FilesForm::onFileUploadComplete(const QString& path) +{ + QListWidgetItem* tmp = new QListWidgetItem(QIcon(":/ui/acceptFileButton/default.png"), path); + sent.addItem(tmp); +} + +// sadly, the ToxFile struct in core only has the file name, not the file path... +// so currently, these don't work as intended (though for now, downloads might work +// whenever they're not saved anywhere custom, thanks to the hack) +// I could do some digging around, but for now I'm tired and others already +// might know it without me needing to dig, so... +void FilesForm::onDownloadFileActivated(QListWidgetItem* item) +{ + QUrl url = QUrl::fromLocalFile("./" + item->text()); + qDebug() << "Opening '" << url << "'"; + QDesktopServices::openUrl(url); +} + +void FilesForm::onUploadFileActivated(QListWidgetItem* item) +{ + QUrl url = QUrl::fromLocalFile(item->text()); + qDebug() << "Opening '" << url << "'"; + QDesktopServices::openUrl(url); +} diff --git a/widget/form/filesform.h b/widget/form/filesform.h new file mode 100644 index 000000000..e7f7fa2ec --- /dev/null +++ b/widget/form/filesform.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2014 by Project Tox + + This file is part of qTox, a Qt-based graphical interface for Tox. + + This program is libre 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 FILESFORM_H +#define FILESFORM_H + +#include "ui_widget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +class FilesForm : public QObject +{ + Q_OBJECT + +public: + FilesForm(); + ~FilesForm(); + + void show(Ui::Widget& ui); + +public slots: + void onFileDownloadComplete(const QString& path); + void onFileUploadComplete(const QString& path); + +private slots: + void onDownloadFileActivated(QListWidgetItem* item); + void onUploadFileActivated(QListWidgetItem* item); + +private: + QWidget* head; + QLabel headLabel; + QVBoxLayout headLayout; + + /* If we really do go whole hog with listing in progress transers, + I should really look into the new fangled list thingy, to deactivate + specific items in the list */ + QTabWidget main; + QListWidget sent, recvd; + +}; + +#include "ui_widget.h" + +#endif // FILESFORM_H diff --git a/widget/widget.cpp b/widget/widget.cpp index a9d4ef8c6..353167cca 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -152,9 +152,10 @@ Widget::Widget(QWidget *parent) : friendListWidget->setLayoutDirection(Qt::LeftToRight); ui->friendList->setWidget(friendListWidget); - ui->nameLabel->setText(Settings::getInstance().getUsername()); + // delay setting username and message until Core inits + //ui->nameLabel->setText(core->getUsername()); ui->nameLabel->label->setStyleSheet("QLabel { color : white; font-size: 11pt; font-weight:bold;}"); - ui->statusLabel->setText(Settings::getInstance().getStatusMessage()); + //ui->statusLabel->setText(core->getStatusMessage()); ui->statusLabel->label->setStyleSheet("QLabel { color : white; font-size: 8pt;}"); ui->friendList->widget()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); @@ -216,6 +217,8 @@ Widget::Widget(QWidget *parent) : connect(core, &Core::usernameSet, this, &Widget::setUsername); connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage); connect(core, &Core::friendAddressGenerated, &settingsForm, &SettingsForm::setFriendAddress); + connect(core, SIGNAL(fileDownloadFinished(const QString&)), &filesForm, SLOT(onFileDownloadComplete(const QString&))); + connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&))); connect(core, &Core::friendAdded, this, &Widget::addFriend); connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed); connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged); @@ -378,7 +381,10 @@ void Widget::onGroupClicked() void Widget::onTransferClicked() { - + hideMainForms(); + filesForm.show(*ui); + isFriendWidgetActive = 0; + isGroupWidgetActive = 0; } void Widget::onSettingsClicked() @@ -430,7 +436,6 @@ void Widget::setUsername(const QString& username) { ui->nameLabel->setText(username); settingsForm.name.setText(username); - Settings::getInstance().setUsername(username); } void Widget::onStatusMessageChanged() @@ -452,7 +457,6 @@ void Widget::setStatusMessage(const QString &statusMessage) { ui->statusLabel->setText(statusMessage); settingsForm.statusText.setText(statusMessage); - Settings::getInstance().setStatusMessage(statusMessage); } void Widget::addFriend(int friendId, const QString &userId) @@ -664,7 +668,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int friendgroupnumber, cons if ((isGroupWidgetActive != 1 || (g->groupId != activeGroupWidget->groupId)) || isWindowMinimized) { - if (message.contains(Settings::getInstance().getUsername(), Qt::CaseInsensitive)) + if (message.contains(core->getUsername(), Qt::CaseInsensitive)) { newMessageAlert(); g->hasNewMessages = 1; diff --git a/widget/widget.h b/widget/widget.h index c452a1564..0e0a13109 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -25,6 +25,7 @@ #include "core.h" #include "widget/form/addfriendform.h" #include "widget/form/settingsform.h" +#include "widget/form/filesform.h" #include "camera.h" #define PIXELS_TO_ACT 7 @@ -34,8 +35,6 @@ class Widget; } class GroupWidget; -class AddFriendForm; -class SettingsForm; struct FriendWidget; class Group; struct Friend; @@ -144,6 +143,7 @@ private: QThread* coreThread; AddFriendForm friendForm; SettingsForm settingsForm; + FilesForm filesForm; static Widget* instance; FriendWidget* activeFriendWidget; GroupWidget* activeGroupWidget;