SVN_SILENT made messages (after extraction)
[kdepim.git] / storageservicemanager / storageservicepage.cpp
blob879a3fee5d96822da3cbc0de98721db502e7c1f9
1 /*
2 Copyright (c) 2013-2016 Montel Laurent <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
21 #include "storageservicepage.h"
22 #include "storageservicetreewidget.h"
23 #include "storageservicewarning.h"
24 #include "storageserviceaccountinfodialog.h"
25 #include "storageservicenavigationbuttons.h"
26 #include "PimCommon/StorageServiceAbstract"
27 #include "PimCommon/StorageServiceProgressWidget"
28 #include "PimCommon/StorageServiceProgressIndicator"
30 #include <KLocalizedString>
31 #include <KMessageBox>
32 #include <knotification.h>
34 #include <QApplication>
35 #include <QClipboard>
36 #include <QVBoxLayout>
37 #include "storageservicemanager_debug.h"
38 #include <QPointer>
39 #include <QTimer>
41 StorageServicePage::StorageServicePage(const QString &serviceName, PimCommon::StorageServiceAbstract *storageService, QWidget *parent)
42 : QWidget(parent),
43 mServiceName(serviceName),
44 mStorageService(storageService)
46 QVBoxLayout *vbox = new QVBoxLayout;
47 setLayout(vbox);
49 mProgressIndicator = new PimCommon::StorageServiceProgressIndicator(this);
50 connect(mProgressIndicator, &PimCommon::StorageServiceProgressIndicator::updatePixmap, this, &StorageServicePage::slotUpdatePixmap);
51 mStorageServiceNavigationBar = new StorageServiceNavigationButtons(this);
52 connect(mStorageServiceNavigationBar, &StorageServiceNavigationButtons::goHome, this, &StorageServicePage::slotGoHome);
53 connect(mStorageServiceNavigationBar, &StorageServiceNavigationButtons::changeUrl, this, &StorageServicePage::slotChangeUrl);
54 mStorageServiceNavigationBar->setEnabled(false);
55 vbox->addWidget(mStorageServiceNavigationBar);
57 mTreeWidget = new StorageServiceTreeWidget(mStorageService);
58 connect(mTreeWidget, &StorageServiceTreeWidget::uploadFile, this, &StorageServicePage::slotUploadFile);
59 connect(mTreeWidget, &StorageServiceTreeWidget::downloadFile, this, &StorageServicePage::slotDownloadFile);
60 connect(mTreeWidget, &StorageServiceTreeWidget::changeFolder, this, &StorageServicePage::slotChangeFolder);
61 connect(mTreeWidget, &StorageServiceTreeWidget::itemSelectionChanged, this, &StorageServicePage::selectionChanged);
62 vbox->addWidget(mTreeWidget);
63 mProgressWidget = new PimCommon::StorageServiceProgressWidget(storageService);
64 vbox->addWidget(mProgressWidget);
65 mProgressWidget->hide();
66 mStorageServiceWarning = new StorageServiceWarning;
67 vbox->addWidget(mStorageServiceWarning);
68 connectStorageService();
71 StorageServicePage::~StorageServicePage()
76 QString StorageServicePage::serviceName() const
78 return mStorageService->storageServiceName();
81 bool StorageServicePage::hasUploadDownloadProgress() const
83 return mStorageService->hasUploadOrDownloadInProgress();
86 void StorageServicePage::slotUpdatePixmap(const QPixmap &pix)
88 if (pix.isNull()) {
89 Q_EMIT updateIcon(mStorageService->icon(), this);
90 } else {
91 Q_EMIT updateIcon(QIcon(pix), this);
95 void StorageServicePage::connectStorageService()
97 connect(mTreeWidget, &StorageServiceTreeWidget::listFileWasInitialized, this, &StorageServicePage::listFileWasInitialized);
98 connect(mStorageService, &PimCommon::StorageServiceAbstract::shareLinkDone, this, &StorageServicePage::slotShareLinkDone);
100 connect(mStorageService, &PimCommon::StorageServiceAbstract::authenticationDone, this, &StorageServicePage::slotAuthenticationDone);
101 connect(mStorageService, &PimCommon::StorageServiceAbstract::authenticationFailed, this, &StorageServicePage::slotAuthenticationFailed);
103 connect(mStorageService, &PimCommon::StorageServiceAbstract::actionFailed, this, &StorageServicePage::slotActionFailed);
105 connect(mStorageService, &PimCommon::StorageServiceAbstract::accountInfoDone, this, &StorageServicePage::slotAccountInfoDone);
107 connect(mStorageService, &PimCommon::StorageServiceAbstract::inProgress, this, &StorageServicePage::slotProgressStateChanged);
109 connect(mStorageService, &PimCommon::StorageServiceAbstract::listFolderDone, this, &StorageServicePage::slotListFolderDone);
111 connect(mStorageService, &PimCommon::StorageServiceAbstract::createFolderDone, this, &StorageServicePage::slotCreateFolderDone);
113 connect(mStorageService, &PimCommon::StorageServiceAbstract::deleteFolderDone, this, &StorageServicePage::slotDeleteFolderDone);
115 connect(mStorageService, &PimCommon::StorageServiceAbstract::deleteFileDone, this, &StorageServicePage::slotDeleteFileDone);
117 connect(mStorageService, &PimCommon::StorageServiceAbstract::renameFolderDone, this, &StorageServicePage::slotRenameFolderDone);
119 connect(mStorageService, &PimCommon::StorageServiceAbstract::renameFileDone, this, &StorageServicePage::slotRenameFileDone);
121 connect(mStorageService, &PimCommon::StorageServiceAbstract::moveFileDone, this, &StorageServicePage::slotMoveFileDone);
123 connect(mStorageService, &PimCommon::StorageServiceAbstract::moveFolderDone, this, &StorageServicePage::slotMoveFolderDone);
125 connect(mStorageService, &PimCommon::StorageServiceAbstract::copyFolderDone, this, &StorageServicePage::slotCopyFolderDone);
127 connect(mStorageService, &PimCommon::StorageServiceAbstract::copyFileDone, this, &StorageServicePage::slotCopyFileDone);
129 connect(mStorageService, &PimCommon::StorageServiceAbstract::downLoadFileDone, this, &StorageServicePage::slotDownloadFileDone);
130 connect(mStorageService, &PimCommon::StorageServiceAbstract::downLoadFileFailed, this, &StorageServicePage::slotDownloadFileFailed);
132 connect(mStorageService, &PimCommon::StorageServiceAbstract::uploadFileFailed, this, &StorageServicePage::slotUploadFileFailed);
133 connect(mStorageService, &PimCommon::StorageServiceAbstract::uploadFileDone, this, &StorageServicePage::slotUploadFileDone);
134 connect(mStorageService, &PimCommon::StorageServiceAbstract::uploadDownloadFileProgress, this, &StorageServicePage::slotuploadDownloadFileProgress);
137 void StorageServicePage::slotRenameFolderDone(const QString &serviceName, const QString &folderName)
139 if (folderName.isEmpty()) {
140 Q_EMIT updateStatusBarMessage(i18n("%1: Folder was renamed.", serviceName));
141 } else {
142 Q_EMIT updateStatusBarMessage(i18n("%1: Folder was renamed to '%2'.", serviceName, folderName));
144 updateList(serviceName);
147 void StorageServicePage::slotRenameFileDone(const QString &serviceName, const QString &fileName)
149 Q_UNUSED(fileName);
150 updateList(serviceName);
153 void StorageServicePage::slotAccountInfoDone(const QString &serviceName, const PimCommon::AccountInfo &accountInfo)
155 if (verifyService(serviceName)) {
156 QPointer<StorageServiceAccountInfoDialog> dlg = new StorageServiceAccountInfoDialog(serviceName, accountInfo, this);
157 dlg->exec();
158 delete dlg;
162 void StorageServicePage::slotUploadFileDone(const QString &serviceName, const QString &fileName)
164 if (verifyService(serviceName)) {
165 mProgressWidget->reset();
166 mProgressWidget->hide();
167 updateList(serviceName);
168 KMessageBox::information(this, fileName.isEmpty() ? i18n("Filename was correctly uploaded") : i18n("%1 was correctly uploaded", fileName), i18n("Upload File"));
172 void StorageServicePage::slotuploadDownloadFileProgress(const QString &serviceName, qint64 done, qint64 total)
174 if (verifyService(serviceName)) {
175 mProgressWidget->setProgressValue(done, total);
179 void StorageServicePage::slotShareLinkDone(const QString &serviceName, const QString &link)
181 if (verifyService(serviceName)) {
182 QClipboard *const cb = QApplication::clipboard();
183 cb->setText(link, QClipboard::Clipboard);
184 KMessageBox::information(this, i18n("Link \'%1\' stored in clipboard", link), i18n("Shared Link"));
188 void StorageServicePage::slotAuthenticationFailed(const QString &serviceName, const QString &error)
190 if (verifyService(serviceName)) {
191 mStorageServiceWarning->addLog(error);
192 mStorageServiceWarning->animatedShow();
196 void StorageServicePage::slotAuthenticationDone(const QString &serviceName)
198 updateList(serviceName);
201 void StorageServicePage::slotActionFailed(const QString &serviceName, const QString &error)
203 if (verifyService(serviceName)) {
204 mStorageServiceWarning->addLog(error);
205 mStorageServiceWarning->animatedShow();
206 KNotification::event(QStringLiteral("action-failed"), error, QPixmap(), this, KNotification::CloseOnTimeout);
210 bool StorageServicePage::verifyService(const QString &serviceName)
212 if (serviceName != mServiceName) {
213 qCDebug(STORAGESERVICEMANAGER_LOG) << " Error in signal/Slots";
214 return false;
216 return true;
219 void StorageServicePage::authenticate()
221 mStorageService->authentication();
224 void StorageServicePage::createFolder()
226 mTreeWidget->slotCreateFolder();
229 void StorageServicePage::accountInfo()
231 mStorageService->accountInfo();
234 void StorageServicePage::slotUploadFile()
236 if (mTreeWidget->uploadFileToService()) {
237 mProgressWidget->reset();
238 mProgressWidget->setProgressBarType(PimCommon::StorageServiceProgressWidget::UploadBar);
239 mProgressWidget->setBusyIndicator(false);
240 mProgressWidget->show();
244 void StorageServicePage::renameItem()
246 mTreeWidget->renameItem();
249 void StorageServicePage::deleteItem()
251 mTreeWidget->deleteItem();
254 void StorageServicePage::downloadFile()
256 mTreeWidget->canDownloadFile();
259 bool StorageServicePage::listFolderWasLoaded() const
261 return mTreeWidget->listFolderWasLoaded();
264 void StorageServicePage::slotDownloadFile()
266 mProgressWidget->reset();
267 mProgressWidget->setProgressBarType(PimCommon::StorageServiceProgressWidget::DownloadBar);
268 mProgressWidget->setBusyIndicator(false);
269 mProgressWidget->show();
270 mTreeWidget->slotDownloadFile();
273 PimCommon::StorageServiceAbstract::Capabilities StorageServicePage::capabilities() const
275 return mStorageService->capabilities();
278 void StorageServicePage::slotProgressStateChanged(bool state)
280 mTreeWidget->setEnabled(!state);
281 mStorageServiceNavigationBar->setEnabled(!state && mTreeWidget->listFolderWasLoaded());
282 if (state) {
283 mProgressIndicator->startAnimation();
284 } else {
285 mProgressIndicator->stopAnimation();
289 void StorageServicePage::slotListFolderDone(const QString &serviceName, const QVariant &data)
291 if (verifyService(serviceName)) {
292 mTreeWidget->setIsInitialized();
293 mTreeWidget->slotListFolderDone(serviceName, data);
297 void StorageServicePage::slotCreateFolderDone(const QString &serviceName, const QString &folder)
299 updateList(serviceName);
300 if (folder.isEmpty()) {
301 Q_EMIT updateStatusBarMessage(i18n("%1: Folder was created.", serviceName));
302 } else {
303 Q_EMIT updateStatusBarMessage(i18n("%1: Folder %2 was created.", serviceName, folder));
307 void StorageServicePage::slotDeleteFolderDone(const QString &serviceName, const QString &folder)
309 updateList(serviceName);
310 if (folder.isEmpty()) {
311 Q_EMIT updateStatusBarMessage(i18n("%1: Folder was deleted.", serviceName));
312 } else {
313 Q_EMIT updateStatusBarMessage(i18n("%1: Folder %2 was deleted.", serviceName, folder));
317 void StorageServicePage::slotDeleteFileDone(const QString &serviceName, const QString &filename)
319 Q_UNUSED(filename);
320 updateList(serviceName);
323 void StorageServicePage::slotMoveFileDone(const QString &serviceName, const QString &filename)
325 Q_UNUSED(filename);
326 updateList(serviceName);
329 void StorageServicePage::slotMoveFolderDone(const QString &serviceName, const QString &filename)
331 Q_UNUSED(filename);
332 updateList(serviceName);
335 void StorageServicePage::slotCopyFileDone(const QString &serviceName, const QString &filename)
337 Q_UNUSED(filename);
338 updateList(serviceName);
341 void StorageServicePage::slotCopyFolderDone(const QString &serviceName, const QString &filename)
343 Q_UNUSED(filename);
344 updateList(serviceName);
347 void StorageServicePage::slotDownloadFileDone(const QString &serviceName, const QString &filename)
349 if (verifyService(serviceName)) {
350 mProgressWidget->reset();
351 mProgressWidget->hide();
352 updateList(serviceName);
353 QString msg;
354 if (filename.isEmpty()) {
355 msg = i18n("File was correctly downloaded.");
356 } else {
357 msg = i18n("%1 was correctly downloaded.", filename);
359 KMessageBox::information(this, msg, i18nc("@title:window", "Download File"));
363 void StorageServicePage::updateList(const QString &serviceName)
365 if (verifyService(serviceName)) {
366 refreshList();
370 void StorageServicePage::refreshList()
372 QTimer::singleShot(0, mTreeWidget, &PimCommon::StorageServiceTreeWidget::refreshList);
375 void StorageServicePage::slotDownloadFileFailed(const QString &serviceName, const QString &filename)
377 if (verifyService(serviceName)) {
378 mProgressWidget->hide();
380 KMessageBox::error(this, i18n("Download Failed"), i18n("Download"));
383 void StorageServicePage::slotUploadFileFailed(const QString &serviceName, const QString &filename)
385 if (verifyService(serviceName)) {
386 mProgressWidget->hide();
388 KMessageBox::error(this, i18n("Upload Failed"), i18n("Upload"));
391 void StorageServicePage::slotGoHome()
393 mTreeWidget->goToFolder(QString());
396 void StorageServicePage::slotChangeFolder(const QString &previousCurrentFolder, const QString &previousParentFolder)
398 InformationUrl info;
399 info.currentUrl = previousCurrentFolder;
400 info.parentUrl = previousParentFolder;
401 mStorageServiceNavigationBar->addNewUrl(info);
404 void StorageServicePage::slotChangeUrl(const InformationUrl &info)
406 mTreeWidget->goToFolder(info.currentUrl, false);
407 mTreeWidget->setParentFolder(info.parentUrl);
410 void StorageServicePage::setNetworkIsDown(bool state)
412 mTreeWidget->setEnabled(!state);
415 void StorageServicePage::showLog()
417 mStorageServiceWarning->showLog();
420 void StorageServicePage::logout()
422 mTreeWidget->logout();
423 mStorageServiceNavigationBar->clear();
424 mStorageServiceNavigationBar->setEnabled(false);
427 PimCommon::StorageServiceTreeWidget::ItemType StorageServicePage::itemTypeSelected() const
429 return mTreeWidget->itemTypeSelected();