File indexing completed on 2024-03-24 05:00:54
0001 // -*- c++ -*- 0002 0003 /* 0004 SPDX-FileCopyrightText: 2003 Richard J. Moore <rich@kde.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "autorefresh.h" 0010 #include <kparts/part.h> 0011 0012 #include <kiconloader.h> 0013 #include <kmessagebox.h> 0014 #include <KLocalizedString> 0015 #include <QTimer> 0016 #include <kselectaction.h> 0017 #include <kactioncollection.h> 0018 #include <kpluginfactory.h> 0019 #include <KParts/ReadOnlyPart> 0020 0021 AutoRefresh::AutoRefresh(QObject *parent, const QVariantList & /*args*/) 0022 : KonqParts::Plugin(parent) 0023 { 0024 timer = new QTimer(this); 0025 connect(timer, &QTimer::timeout, this, &AutoRefresh::slotRefresh); 0026 0027 refresher = actionCollection()->add<KSelectAction>(QStringLiteral("autorefresh")); 0028 refresher->setText(i18n("&Auto Refresh")); 0029 refresher->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); 0030 connect(refresher, SIGNAL(triggered(QAction*)), this, SLOT(slotIntervalChanged())); 0031 QStringList sl; 0032 sl << i18n("None"); 0033 sl << i18n("Every 15 Seconds"); 0034 sl << i18n("Every 30 Seconds"); 0035 sl << i18n("Every Minute"); 0036 sl << i18n("Every 5 Minutes"); 0037 sl << i18n("Every 10 Minutes"); 0038 sl << i18n("Every 15 Minutes"); 0039 sl << i18n("Every 30 Minutes"); 0040 sl << i18n("Every 60 Minutes"); 0041 sl << i18n("Every 2 Hours"); 0042 sl << i18n("Every 6 Hours"); 0043 0044 refresher->setItems(sl); 0045 refresher->setCurrentItem(0); 0046 } 0047 0048 AutoRefresh::~AutoRefresh() 0049 { 0050 } 0051 0052 void AutoRefresh::slotIntervalChanged() 0053 { 0054 int idx = refresher->currentItem(); 0055 int timeout = 0; 0056 switch (idx) { 0057 case 1: 0058 timeout = (15 * 1000); 0059 break; 0060 case 2: 0061 timeout = (30 * 1000); 0062 break; 0063 case 3: 0064 timeout = (60 * 1000); 0065 break; 0066 case 4: 0067 timeout = (5 * 60 * 1000); 0068 break; 0069 case 5: 0070 timeout = (10 * 60 * 1000); 0071 break; 0072 case 6: 0073 timeout = (15 * 60 * 1000); 0074 break; 0075 case 7: 0076 timeout = (30 * 60 * 1000); 0077 break; 0078 case 8: 0079 timeout = (60 * 60 * 1000); 0080 break; 0081 case 9: 0082 timeout = (2 * 60 * 60 * 1000); 0083 break; 0084 case 10: 0085 timeout = (6 * 60 * 60 * 1000); 0086 break; 0087 default: 0088 break; 0089 } 0090 timer->stop(); 0091 if (timeout) { 0092 timer->start(timeout); 0093 } 0094 } 0095 0096 void AutoRefresh::slotRefresh() 0097 { 0098 KParts::ReadOnlyPart *part = qobject_cast< KParts::ReadOnlyPart * >(parent()); 0099 if (!part) { 0100 QString title = i18nc("@title:window", "Cannot Refresh Source"); 0101 QString text = i18n("<qt>This plugin cannot auto-refresh the current part.</qt>"); 0102 0103 KMessageBox::error(nullptr, text, title); 0104 } else { 0105 // Get URL 0106 QUrl url = part->url(); 0107 part->openUrl(url); 0108 } 0109 } 0110 0111 K_PLUGIN_CLASS_WITH_JSON(AutoRefresh, "autorefresh.json") 0112 0113 #include "autorefresh.moc" 0114