Messagelib

opensavedfilefolderwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2014-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "opensavedfilefolderwidget.h"
8 
9 #include <KIO/OpenFileManagerWindowJob>
10 #include <KLocalizedString>
11 
12 #include <QTimer>
13 
14 #include <QAction>
15 #include <chrono>
16 
17 using namespace std::chrono_literals;
18 using namespace MessageViewer;
19 
20 OpenSavedFileFolderWidget::OpenSavedFileFolderWidget(QWidget *parent)
21  : KMessageWidget(parent)
22  , mTimer(new QTimer(this))
23  , mShowFolderAction(new QAction(i18nc("@action", "Open folder where attachment was saved"), this))
24 {
25  mTimer->setSingleShot(true);
26  mTimer->setInterval(5s); // 5 seconds
27  connect(mTimer, &QTimer::timeout, this, &OpenSavedFileFolderWidget::slotTimeOut);
28  setVisible(false);
29  setCloseButtonVisible(true);
30  setMessageType(Positive);
31  setWordWrap(true);
32  auto action = this->findChild<QAction *>(); // should give us the close action...
33  if (action) {
34  connect(action, &QAction::triggered, this, &OpenSavedFileFolderWidget::slotExplicitlyClosed);
35  }
36 
37  connect(mShowFolderAction, &QAction::triggered, this, &OpenSavedFileFolderWidget::slotOpenSavedFileFolder);
38  addAction(mShowFolderAction);
39 }
40 
41 OpenSavedFileFolderWidget::~OpenSavedFileFolderWidget() = default;
42 
43 void OpenSavedFileFolderWidget::slotExplicitlyClosed()
44 {
45  if (mTimer->isActive()) {
46  mTimer->stop();
47  }
48 }
49 
50 void OpenSavedFileFolderWidget::setUrls(const QList<QUrl> &urls, FileType fileType)
51 {
52  mUrls = urls;
53  switch (fileType) {
54  case FileType::Attachment:
55  mShowFolderAction->setText(i18np("Open folder where attachment was saved", "Open folder where attachments were saved", mUrls.count()));
56  break;
57  case FileType::Pdf:
58  mShowFolderAction->setText(i18n("Open folder where PDF file was saved"));
59  break;
60  }
61 }
62 
63 void OpenSavedFileFolderWidget::slotOpenSavedFileFolder()
64 {
65  if (!mUrls.isEmpty()) {
67  slotHideWarning();
68  }
69 }
70 
71 void OpenSavedFileFolderWidget::slotHideWarning()
72 {
73  if (mTimer->isActive()) {
74  mTimer->stop();
75  }
76  animatedHide();
77 }
78 
79 void OpenSavedFileFolderWidget::slotShowWarning()
80 {
81  if (mTimer->isActive()) {
82  mTimer->stop();
83  }
84  mTimer->start();
85  animatedShow();
86 }
87 
88 void OpenSavedFileFolderWidget::slotTimeOut()
89 {
90  animatedHide();
91 }
void triggered(bool checked)
OpenFileManagerWindowJob * highlightInFileManager(const QList< QUrl > &urls, const QByteArray &asn=QByteArray())
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
void timeout()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.