mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #126 from dubslow/master
Add the files transfered Widget
This commit is contained in:
commit
2af720877f
40
core.cpp
40
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<TOXAV_MAX_CALLS;i++)
|
||||
{
|
||||
|
@ -562,6 +563,17 @@ void Core::removeGroup(int groupId)
|
|||
tox_del_groupchat(tox, groupId);
|
||||
}
|
||||
|
||||
QString Core::getUsername()
|
||||
{
|
||||
int size = tox_get_self_name_size(tox);
|
||||
uint8_t* name = new uint8_t[size];
|
||||
if (tox_get_self_name(tox, name) == size)
|
||||
return QString(CString::toString(name, size));
|
||||
else
|
||||
return QString();
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
void Core::setUsername(const QString& username)
|
||||
{
|
||||
CString cUsername(username);
|
||||
|
@ -574,6 +586,17 @@ void Core::setUsername(const QString& username)
|
|||
}
|
||||
}
|
||||
|
||||
QString Core::getStatusMessage()
|
||||
{
|
||||
int size = tox_get_self_status_message_size(tox);
|
||||
uint8_t* name = new uint8_t[size];
|
||||
if (tox_get_self_status_message(tox, name, size) == size)
|
||||
return QString(CString::toString(name, size));
|
||||
else
|
||||
return QString();
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
void Core::setStatusMessage(const QString& message)
|
||||
{
|
||||
CString cMessage(message);
|
||||
|
@ -612,6 +635,14 @@ void Core::setStatus(Status status)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::onFileTransferFinished(ToxFile file)
|
||||
{
|
||||
if (file.direction == file.SENDING)
|
||||
emit fileUploadFinished(QString(file.fileName));
|
||||
else
|
||||
emit fileDownloadFinished(QString(file.fileName));
|
||||
}
|
||||
|
||||
void Core::bootstrapDht()
|
||||
{
|
||||
qDebug() << "Core: Bootstraping DHT";
|
||||
|
@ -688,6 +719,15 @@ void Core::loadConfiguration()
|
|||
|
||||
configurationFile.close();
|
||||
|
||||
// set GUI with user and statusmsg
|
||||
QString name = getUsername();
|
||||
if (name != "")
|
||||
emit usernameSet(name);
|
||||
|
||||
QString msg = getStatusMessage();
|
||||
if (msg != "")
|
||||
emit statusMessageSet(msg);
|
||||
|
||||
loadFriends();
|
||||
}
|
||||
|
||||
|
|
8
core.h
8
core.h
|
@ -120,6 +120,9 @@ public:
|
|||
void dispatchVideoFrame(vpx_image img) const;
|
||||
|
||||
void saveConfiguration();
|
||||
|
||||
QString getUsername();
|
||||
QString getStatusMessage();
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
|
@ -207,6 +210,8 @@ signals:
|
|||
void fileTransferAccepted(ToxFile file);
|
||||
void fileTransferCancelled(int FriendId, int FileNum, ToxFile::FileDirection direction);
|
||||
void fileTransferFinished(ToxFile file);
|
||||
void fileUploadFinished(const QString& path);
|
||||
void fileDownloadFinished(const QString& path);
|
||||
void fileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection direction);
|
||||
void fileTransferInfo(int FriendId, int FileNum, int Filesize, int BytesSent, ToxFile::FileDirection direction);
|
||||
|
||||
|
@ -270,6 +275,9 @@ private:
|
|||
|
||||
void checkLastOnline(int friendId);
|
||||
|
||||
private slots:
|
||||
void onFileTransferFinished(ToxFile file);
|
||||
|
||||
private:
|
||||
Tox* tox;
|
||||
ToxAv* toxav;
|
||||
|
|
2
main.cpp
2
main.cpp
|
@ -23,7 +23,7 @@
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setApplicationName("Toxgui");
|
||||
a.setApplicationName("qTox");
|
||||
a.setOrganizationName("Tox");
|
||||
|
||||
// Load translations
|
||||
|
|
24
settings.cpp
24
settings.cpp
|
@ -73,8 +73,6 @@ void Settings::load()
|
|||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
username = s.value("username", "My name").toString();
|
||||
statusMessage = s.value("statusMessage", "My status").toString();
|
||||
enableIPv6 = s.value("enableIPv6", true).toBool();
|
||||
useTranslations = s.value("useTranslations", true).toBool();
|
||||
s.endGroup();
|
||||
|
@ -126,8 +124,6 @@ void Settings::save()
|
|||
s.endGroup();
|
||||
|
||||
s.beginGroup("General");
|
||||
s.setValue("username", username);
|
||||
s.setValue("statusMessage", statusMessage);
|
||||
s.setValue("enableIPv6", enableIPv6);
|
||||
s.setValue("useTranslations",useTranslations);
|
||||
s.endGroup();
|
||||
|
@ -177,26 +173,6 @@ void Settings::setDhtServerList(const QList<DhtServer>& 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;
|
||||
|
|
|
@ -43,12 +43,6 @@ public:
|
|||
const QList<DhtServer>& getDhtServerList() const;
|
||||
void setDhtServerList(const QList<DhtServer>& 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;
|
||||
|
||||
|
|
|
@ -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 \
|
||||
|
|
83
widget/form/filesform.cpp
Normal file
83
widget/form/filesform.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
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);
|
||||
}
|
64
widget/form/filesform.h
Normal file
64
widget/form/filesform.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
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 <QListWidget>
|
||||
#include <QTabWidget>
|
||||
#include <QString>
|
||||
#include <QDesktopServices>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
|
||||
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
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user