1 /*
2 Copyright © 2014-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 "filesform.h"
21 #include "src/widget/contentlayout.h"
22 #include "src/widget/translator.h"
23 #include "src/widget/style.h"
24 #include "src/widget/widget.h"
25 #include <QFileInfo>
26 #include <QWindow>
27
FilesForm()28 FilesForm::FilesForm()
29 : QObject()
30 , doneIcon(Style::getImagePath("fileTransferWidget/fileDone.svg"))
31 {
32 head = new QWidget();
33 QFont bold;
34 bold.setBold(true);
35 headLabel.setFont(bold);
36 head->setLayout(&headLayout);
37 headLayout.addWidget(&headLabel);
38
39 recvd = new QListWidget;
40 sent = new QListWidget;
41
42 main.addTab(recvd, QString());
43 main.addTab(sent, QString());
44
45 connect(sent, &QListWidget::itemActivated, this, &FilesForm::onFileActivated);
46 connect(recvd, &QListWidget::itemActivated, this, &FilesForm::onFileActivated);
47
48 retranslateUi();
49 Translator::registerHandler(std::bind(&FilesForm::retranslateUi, this), this);
50 }
51
~FilesForm()52 FilesForm::~FilesForm()
53 {
54 Translator::unregister(this);
55 delete recvd;
56 delete sent;
57 head->deleteLater();
58 }
59
isShown() const60 bool FilesForm::isShown() const
61 {
62 if (main.isVisible()) {
63 head->window()->windowHandle()->alert(0);
64 return true;
65 }
66
67 return false;
68 }
69
show(ContentLayout * contentLayout)70 void FilesForm::show(ContentLayout* contentLayout)
71 {
72 contentLayout->mainContent->layout()->addWidget(&main);
73 contentLayout->mainHead->layout()->addWidget(head);
74 main.show();
75 head->show();
76 }
77
onFileDownloadComplete(const QString & path)78 void FilesForm::onFileDownloadComplete(const QString& path)
79 {
80 QListWidgetItem* tmp = new QListWidgetItem(doneIcon, QFileInfo(path).fileName());
81 tmp->setData(Qt::UserRole, path);
82 recvd->addItem(tmp);
83 }
84
onFileUploadComplete(const QString & path)85 void FilesForm::onFileUploadComplete(const QString& path)
86 {
87 QListWidgetItem* tmp = new QListWidgetItem(doneIcon, QFileInfo(path).fileName());
88 tmp->setData(Qt::UserRole, path);
89 sent->addItem(tmp);
90 }
91
92 // sadly, the ToxFile struct in core only has the file name, not the file path...
93 // so currently, these don't work as intended (though for now, downloads might work
94 // whenever they're not saved anywhere custom, thanks to the hack)
95 // I could do some digging around, but for now I'm tired and others already
96 // might know it without me needing to dig, so...
onFileActivated(QListWidgetItem * item)97 void FilesForm::onFileActivated(QListWidgetItem* item)
98 {
99 Widget::confirmExecutableOpen(QFileInfo(item->data(Qt::UserRole).toString()));
100 }
101
retranslateUi()102 void FilesForm::retranslateUi()
103 {
104 headLabel.setText(tr("Transferred Files", "\"Headline\" of the window"));
105 main.setTabText(0, tr("Downloads"));
106 main.setTabText(1, tr("Uploads"));
107 }
108