From 26f2f143fa57797fbf50963daee614eb96d6cbb2 Mon Sep 17 00:00:00 2001 From: Bill Winslow Date: Fri, 11 Jul 2014 12:05:18 -0400 Subject: [PATCH] Initial commit for activating the file transfer button It compiles, but is in fact untested (and requires one small new icon) --- core.cpp | 9 +++++ core.h | 5 +++ main.cpp | 2 +- toxgui.pro | 2 ++ widget/form/filesform.cpp | 72 +++++++++++++++++++++++++++++++++++++++ widget/form/filesform.h | 62 +++++++++++++++++++++++++++++++++ widget/widget.cpp | 7 +++- widget/widget.h | 6 ++-- 8 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 widget/form/filesform.cpp create mode 100644 widget/form/filesform.h diff --git a/core.cpp b/core.cpp index 98076fc7d..7b27e0f26 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 + + 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")); + + //these need to go in widget.cpp (I think, not really sure atm) + //connect(something, SIGNAL(DOWNLOAD_DONE), this, SLOT(onFileDownloadComplete())); + //connect(something, SIGNAL(DOWNLOAD_DONE), this, SLOT(onFileUploadComplete())); + + connect(&sent, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(onFileActivated(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("checkmark.png"),*/path); + recvd.addItem(tmp); +} + +void FilesForm::onFileUploadComplete(const QString& path) +{ + QListWidgetItem* tmp = new QListWidgetItem(/*QIcon("checkmark.png"),*/path); + sent.addItem(tmp); +} + +void FilesForm::onFileActivated(QListWidgetItem* item) +{ + QDesktopServices::openUrl(QUrl::fromLocalFile(item->text())); +} diff --git a/widget/form/filesform.h b/widget/form/filesform.h new file mode 100644 index 000000000..9f26fd6ee --- /dev/null +++ b/widget/form/filesform.h @@ -0,0 +1,62 @@ +/* + 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 + +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 onFileActivated(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 d6db2bfc4..a27f8be97 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -215,6 +215,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(Core::fileDownloadFinished(QString&)), &filesForm, SLOT(FilesForm::onFileDownloadComplete(QString&))); + connect(core, SIGNAL(Core::fileUploadFinished(QString&)), &filesForm, SLOT(FilesForm::onFileUploadComplete(QString&))); connect(core, &Core::friendAdded, this, &Widget::addFriend); connect(core, &Core::failedToAddFriend, this, &Widget::addFriendFailed); connect(core, &Core::friendStatusChanged, this, &Widget::onFriendStatusChanged); @@ -377,7 +379,10 @@ void Widget::onGroupClicked() void Widget::onTransferClicked() { - + hideMainForms(); + filesForm.show(*ui); + isFriendWidgetActive = 0; + isGroupWidgetActive = 0; } void Widget::onSettingsClicked() diff --git a/widget/widget.h b/widget/widget.h index c452a1564..f7e6982d6 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,8 @@ class Widget; } class GroupWidget; -class AddFriendForm; -class SettingsForm; +//class AddFriendForm; +//class SettingsForm; struct FriendWidget; class Group; struct Friend; @@ -144,6 +145,7 @@ private: QThread* coreThread; AddFriendForm friendForm; SettingsForm settingsForm; + FilesForm filesForm; static Widget* instance; FriendWidget* activeFriendWidget; GroupWidget* activeGroupWidget;