diff --git a/applets/comic/comicarchivejob.cpp b/applets/comic/comicarchivejob.cpp index 27f4918d0..08db9f023 100644 --- a/applets/comic/comicarchivejob.cpp +++ b/applets/comic/comicarchivejob.cpp @@ -1,401 +1,401 @@ /*************************************************************************** * Copyright (C) 2011 Matthias Fuchs * * Copyright (C) 2015 Marco Martin * * * * This program is free 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 2 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 * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "comicarchivejob.h" #include #include #include #include #include ComicArchiveJob::ComicArchiveJob( const QUrl &dest, Plasma::DataEngine *engine, ComicArchiveJob::ArchiveType archiveType, IdentifierType identifierType, const QString &pluginName, QObject *parent ) : KJob( parent ), mType( archiveType ), mDirection( Undefined ), mIdentifierType( identifierType ), mSuspend( false ), mFindAmount( true ), mHasVariants( false ), mDone( false ), mComicNumber( 0 ), mProcessedFiles( 0 ), mTotalFiles( -1 ), mEngine( engine ), mZipFile( new QTemporaryFile ), mZip(nullptr), mPluginName( pluginName ), mDest( dest ) { if ( mZipFile->open() ) { mZip = new KZip( mZipFile->fileName() ); mZip->open( QIODevice::ReadWrite ); mZip->setCompression( KZip::NoCompression ); setCapabilities( Killable | Suspendable ); } else { qWarning() << "Could not create a temporary file for the zip file."; } } ComicArchiveJob::~ComicArchiveJob() { emitResultIfNeeded(); delete mZip; delete mZipFile; qDeleteAll( mBackwardFiles ); } bool ComicArchiveJob::isValid() const { if ( mPluginName.isEmpty() ) { qWarning() << "No plugin name specified."; return false; } switch ( mType ) { case ArchiveFromTo: if ( mToIdentifier.isEmpty() || mFromIdentifier.isEmpty() ) { qWarning() << "Not enough data provided to archive a range."; return false; } break; case ArchiveStartTo: case ArchiveEndTo: if ( mToIdentifier.isEmpty() ) { - qWarning() << "Not enough data provied to archive StartTo/EndTo."; + qWarning() << "Not enough data provided to archive StartTo/EndTo."; return false; } break; default: break; } return mEngine->isValid() && mZip && mZip->isOpen(); } void ComicArchiveJob::setToIdentifier( const QString &toIdentifier ) { mToIdentifier = toIdentifier; mToIdentifierSuffix = mToIdentifier; mToIdentifierSuffix.remove(mPluginName + QLatin1Char(':')); } void ComicArchiveJob::setFromIdentifier( const QString &fromIdentifier ) { mFromIdentifier = fromIdentifier; mFromIdentifierSuffix = mFromIdentifier; mFromIdentifierSuffix.remove(mPluginName + QLatin1Char(':')); } void ComicArchiveJob::start() { switch ( mType ) { case ArchiveAll: requestComic( suffixToIdentifier( QString() ) ); break; case ArchiveStartTo: requestComic( mToIdentifier ); break; case ArchiveEndTo: { setFromIdentifier( mToIdentifier ); mToIdentifier.clear(); mToIdentifierSuffix.clear(); requestComic( suffixToIdentifier( QString() ) ); break; } case ArchiveFromTo: mDirection = Forward; defineTotalNumber(); requestComic( mFromIdentifier ); break; } } void ComicArchiveJob::dataUpdated( const QString &source, const Plasma::DataEngine::Data &data ) { if ( !mZip ) { qWarning() << "No zip file, aborting."; setErrorText( i18n( "No zip file is existing, aborting." ) ); setError( KilledJobError ); emitResultIfNeeded(); return; } const QString currentIdentifier = data[QStringLiteral("Identifier")].toString(); QString currentIdentifierSuffix = currentIdentifier; currentIdentifierSuffix.remove(mPluginName + QLatin1Char(':')); const QImage image = data[QStringLiteral("Image")].value(); const bool hasError = data[QStringLiteral("Error")].toBool() || image.isNull(); const QString previousIdentifierSuffix = data[QStringLiteral("Previous identifier suffix")].toString(); const QString nextIdentifierSuffix = data[QStringLiteral("Next identifier suffix")].toString(); const QString firstIdentifierSuffix = data[QStringLiteral("First strip identifier suffix")].toString(); mAuthors << data[QStringLiteral("Comic Author")].toString().split(QLatin1Char(','), QString::SkipEmptyParts); mAuthors.removeDuplicates(); if ( mComicTitle.isEmpty() ) { mComicTitle = data[QStringLiteral("Title")].toString(); } if ( hasError ) { qWarning() << "An error occurred at" << source << "stopping."; setErrorText( i18n( "An error happened for identifier %1.", source ) ); setError( KilledJobError ); copyZipFileToDestination(); return; } if ( mDirection == Undefined ) { if ( ( mType == ArchiveAll ) || ( mType == ArchiveStartTo ) ) { if ( !firstIdentifierSuffix.isEmpty() ) { setFromIdentifier( suffixToIdentifier( firstIdentifierSuffix ) ); } if ( mType == ArchiveAll ) { setToIdentifier( currentIdentifier ); } mDirection = ( firstIdentifierSuffix.isEmpty() ? Backward : Forward ); if ( mDirection == Forward ) { requestComic( suffixToIdentifier( firstIdentifierSuffix ) ); return; } else { //backward, i.e. the to identifier is unknown mToIdentifier.clear(); mToIdentifierSuffix.clear(); } } else if ( mType == ArchiveEndTo ) { mDirection = Forward; setToIdentifier( currentIdentifier ); requestComic( mFromIdentifier ); return; } } bool worked = false; ++mProcessedFiles; if ( mDirection == Forward ) { QTemporaryFile tempFile; worked = tempFile.open(); worked = worked && tempFile.flush(); worked = ( worked ? image.save( tempFile.fileName(), "PNG" ) : worked ); worked = ( worked ? addFileToZip( tempFile.fileName() ) : worked ); if ( worked ) { if ( ( currentIdentifier == mToIdentifier ) || ( currentIdentifierSuffix == nextIdentifierSuffix) || nextIdentifierSuffix.isEmpty() ) { qDebug() << "Done downloading at:" << source; copyZipFileToDestination(); } else { requestComic( suffixToIdentifier( nextIdentifierSuffix ) ); } } } else if ( mDirection == Backward ) { QTemporaryFile *tempFile = new QTemporaryFile; mBackwardFiles << tempFile; worked = tempFile->open(); worked = worked && tempFile->flush(); worked = ( worked ? image.save( tempFile->fileName(), "PNG" ) : worked ); if ( worked ) { if ( ( currentIdentifier == mToIdentifier ) || ( currentIdentifierSuffix == previousIdentifierSuffix ) || previousIdentifierSuffix.isEmpty() ) { qDebug() << "Done downloading at:" << source; createBackwardZip(); } else { requestComic( suffixToIdentifier( previousIdentifierSuffix) ); } } } defineTotalNumber( currentIdentifierSuffix ); setProcessedAmount( Files, mProcessedFiles ); if ( mTotalFiles != -1 ) { setPercent( ( 100 * mProcessedFiles ) / mTotalFiles ); } if ( !worked ) { qWarning() << "Could not write the file, identifier:" << source; setErrorText( i18n( "Failed creating the file with identifier %1.", source ) ); setError( KilledJobError ); emitResultIfNeeded(); } mEngine->disconnectSource( source, this ); } bool ComicArchiveJob::doKill() { mSuspend = true; return KJob::doKill(); } bool ComicArchiveJob::doSuspend() { mSuspend = true; return true; } bool ComicArchiveJob::doResume() { mSuspend = false; if ( !mRequest.isEmpty() ) { requestComic( mRequest ); } return true; } void ComicArchiveJob::defineTotalNumber( const QString ¤tSuffix ) { findTotalNumberFromTo(); if ( mTotalFiles == -1 ) { qDebug() << "Unable to find the total number for" << mPluginName; return; } //calculate a new value for total files, can be different from the previous one, //if there are no strips for certain days/numbers if ( !currentSuffix.isEmpty() ) { if ( mIdentifierType == Date ) { const QDate current = QDate::fromString(currentSuffix, QStringLiteral("yyyy-MM-dd")); const QDate to = QDate::fromString(mToIdentifierSuffix, QStringLiteral("yyyy-MM-dd")); if ( current.isValid() && to.isValid() ) { //processed files + files still to download mTotalFiles = mProcessedFiles + qAbs( current.daysTo( to ) ); } } else if ( mIdentifierType == Number ) { bool result = true; bool ok; const int current = currentSuffix.toInt( &ok ); result = ( result && ok ); const int to = mToIdentifierSuffix.toInt( &ok ); result = ( result && ok ); if ( result ) { //processed files + files still to download mTotalFiles = mProcessedFiles + qAbs( to - current ); } } } if ( mTotalFiles != -1 ) { setTotalAmount( Files, mTotalFiles ); } } void ComicArchiveJob::findTotalNumberFromTo() { if ( mTotalFiles != -1 ) { return; } if ( mIdentifierType == Date ) { const QDate from = QDate::fromString( mFromIdentifierSuffix, QStringLiteral("yyyy-MM-dd")); const QDate to = QDate::fromString(mToIdentifierSuffix, QStringLiteral("yyyy-MM-dd")); if ( from.isValid() && to.isValid() ) { mTotalFiles = qAbs( from.daysTo( to ) ) + 1; } } else if ( mIdentifierType == Number ) { bool result = true; bool ok; const int from = mFromIdentifierSuffix.toInt( &ok ); result = ( result && ok ); const int to = mToIdentifierSuffix.toInt( &ok ); result = ( result && ok ); if ( result ) { mTotalFiles = qAbs( to - from ) + 1; } } } QString ComicArchiveJob::suffixToIdentifier( const QString &suffix ) const { return mPluginName + QLatin1Char(':') + suffix; } void ComicArchiveJob::requestComic( QString identifier ) //krazy:exclude=passbyvalue { mRequest.clear(); if ( mSuspend ) { mRequest = identifier; return; } emit description( this, i18n( "Creating Comic Book Archive" ), qMakePair(QStringLiteral("source"), identifier), qMakePair(QStringLiteral("destination"), mDest.toString())); mEngine->connectSource( identifier, this ); // mEngine->query( identifier ); } bool ComicArchiveJob::addFileToZip( const QString &path ) { //We use 6 signs, e.g. number 1 --> 000001.png, 123 --> 000123.png //this way the comics should always be correctly sorted (otherwise evince e.g. has problems) static const int numSigns = 6; static const QString zero = QLatin1String( "0" ); QString number = QString::number( ++mComicNumber ); const int length = number.length(); if ( length < numSigns ) { number = zero.repeated( numSigns - length ) + number; } return mZip->addLocalFile( path, number + QLatin1String( ".png" ) ); } void ComicArchiveJob::createBackwardZip() { for ( int i = mBackwardFiles.count() - 1; i >= 0; --i ) { if ( !addFileToZip( mBackwardFiles[i]->fileName() ) ) { qWarning() << "Failed adding a file to the archive."; setErrorText( i18n( "Failed adding a file to the archive." ) ); setError( KilledJobError ); emitResultIfNeeded(); return; } } copyZipFileToDestination(); } void ComicArchiveJob::copyZipFileToDestination() { mZip->close(); KIO::FileCopyJob *job = KIO::file_copy( QUrl::fromLocalFile( mZipFile->fileName() ), mDest ); const bool worked = job->exec(); if (!worked) { qWarning() << "Could not copy the zip file to the specified destination:" << mDest; setErrorText( i18n( "Could not create the archive at the specified location." ) ); setError( KilledJobError ); emitResultIfNeeded(); return; } emitResultIfNeeded(); } void ComicArchiveJob::emitResultIfNeeded() { if ( !mDone ) { mDone = true; emitResult(); } } diff --git a/applets/comic/stripselector.h b/applets/comic/stripselector.h index bdc34cc83..2fe810ead 100644 --- a/applets/comic/stripselector.h +++ b/applets/comic/stripselector.h @@ -1,72 +1,72 @@ /*************************************************************************** * Copyright (C) 2012 Matthias Fuchs * * * * This program is free 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 2 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 * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef STRIP_SELECTOR_H #define STRIP_SELECTOR_H #include #include "comicinfo.h" class ComicData; class QDate; /** * Enables users to visually select a strip they want to navigate to. * Subclasses implement different Selectors for the different comic * types. * @note use the StripSelectorFactory to retrieve an appropriate * StripSelector */ class StripSelector : public QObject { Q_OBJECT public: ~StripSelector() override; /** * Select a strip depending on the subclass * @param currentStrip the currently active strip * @note StripSelector takes care to delete itself */ virtual void select(const ComicData ¤tStrip) = 0; Q_SIGNALS: /** * @param strip the selected strip, can be empty * */ void stripChosen(const QString &strip); protected: explicit StripSelector(QObject *parent = nullptr); }; /** - * Class to retrrieve the correct StripSelector depending on the + * Class to retrieve the correct StripSelector depending on the * specified IdentifierType */ class StripSelectorFactory { public: static StripSelector *create(IdentifierType type); }; #endif diff --git a/applets/minimizeall/package/contents/ui/main.qml b/applets/minimizeall/package/contents/ui/main.qml index a785676eb..17ac18bdd 100644 --- a/applets/minimizeall/package/contents/ui/main.qml +++ b/applets/minimizeall/package/contents/ui/main.qml @@ -1,172 +1,172 @@ /* * Copyright 2015 Sebastian Kügler * Copyright 2016 Anthony Fieroni * Copyright 2018 David Edmundson * * This program is free 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 2 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ import QtQuick 2.7 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.taskmanager 0.1 as TaskManager Item { id: root readonly property bool inPanel: (plasmoid.location === PlasmaCore.Types.TopEdge || plasmoid.location === PlasmaCore.Types.RightEdge || plasmoid.location === PlasmaCore.Types.BottomEdge || plasmoid.location === PlasmaCore.Types.LeftEdge) Layout.minimumWidth: units.gridUnit Layout.minimumHeight: units.gridUnit Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1 Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1 Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation Plasmoid.onActivated: toggleActive() property bool active: false property var minimizedClients: [] //list of persistentmodelindexes from task manager model of clients minimised by us function activate() { var clients = [] for (var i = 0 ; i < tasksModel.count; i++) { var idx = tasksModel.makeModelIndex(i); if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { tasksModel.requestToggleMinimized(idx); clients.push(tasksModel.makePersistentModelIndex(i)); } } root.minimizedClients = clients; root.active = true; } function deactivate() { root.active = false; for (var i = 0 ; i < root.minimizedClients.length; i++) { var idx = root.minimizedClients[i] //client deleted, do nothing if (!idx.valid) { continue; } //if the user has restored it already, do nothing if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) { continue; } tasksModel.requestToggleMinimized(idx); } root.minimizedClients = []; } function toggleActive() { if (root.active) { deactivate(); } else { activate(); } } TaskManager.TasksModel { id: tasksModel sortMode: TaskManager.TasksModel.SortDisabled groupMode: TaskManager.TasksModel.GroupDisabled } Connections { target: tasksModel enabled: root.active onActiveTaskChanged: { - if (tasksModel.activeTask.valid) { //to supress changing focus to non windows, such as the desktop + if (tasksModel.activeTask.valid) { //to suppress changing focus to non windows, such as the desktop root.active = false; root.minimizedClients = []; } } onVirtualDesktopChanged: deactivate() onActivityChanged: deactivate() } PlasmaCore.FrameSvgItem { id: expandedItem anchors.fill: parent imagePath: "widgets/tabbar" prefix: { var prefix; switch (plasmoid.location) { case PlasmaCore.Types.LeftEdge: prefix = "west-active-tab"; break; case PlasmaCore.Types.TopEdge: prefix = "north-active-tab"; break; case PlasmaCore.Types.RightEdge: prefix = "east-active-tab"; break; default: prefix = "south-active-tab"; } if (!hasElementPrefix(prefix)) { prefix = "active-tab"; } return prefix; } opacity: root.active ? 1 : 0 Behavior on opacity { NumberAnimation { duration: units.shortDuration easing.type: Easing.InOutQuad } } } PlasmaCore.IconItem { id:icon source: plasmoid.configuration.icon active: tooltip.containsMouse anchors.fill: parent } PlasmaCore.ToolTipArea { id: tooltip anchors.fill: parent mainText : i18n("Minimize Windows") subText : i18n("Show the desktop by minimizing all windows") icon : plasmoid.configuration.icon MouseArea { id: mouseArea anchors.fill: parent onClicked: root.toggleActive() } //also activate when dragging an item over the plasmoid so a user can easily drag data to the desktop DropArea { anchors.fill: parent onEntered: activateTimer.start() onExited: activateTimer.stop() Timer { id: activateTimer interval: 250 //to match TaskManager onTriggered: toggleActive() } } } } diff --git a/dataengines/comic/cachedprovider.h b/dataengines/comic/cachedprovider.h index ebf8fb85d..910843031 100644 --- a/dataengines/comic/cachedprovider.h +++ b/dataengines/comic/cachedprovider.h @@ -1,168 +1,168 @@ /* * Copyright (C) 2007 Tobias Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CACHEDPROVIDER_H #define CACHEDPROVIDER_H #include "comicprovider.h" #include /** * This class provides comics from the local cache. */ class CachedProvider : public ComicProvider { Q_OBJECT public: /** * Creates a new cached provider. * - * @param identifier The identifier of the cached comic. * @param parent The parent object. + * param args The arguments. */ explicit CachedProvider(QObject *parent, const QVariantList &args = QVariantList()); /** * Destroys the cached provider. */ ~CachedProvider() override; /** * Returns the identifier type. * * Is always StringIdentifier here. */ IdentifierType identifierType() const override; /** * Returns the type of identifier that is used by this * comic provider. */ QString suffixType() const override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; /** * Returns the identifier of the comic request (name + date). */ QString identifier() const override; /** * Returns the identifier suffix of the next comic. */ QString nextIdentifier() const override; /** * Returns the identifier suffix of the previous comic. */ QString previousIdentifier() const override; /** * Returns the identifier of the first strip. */ QString firstStripIdentifier() const override; /** * Returns the identifier of the last cached strip. */ QString lastCachedStripIdentifier() const; /** * Returns the title of the strip. */ QString stripTitle() const override; /** * Returns the author of the comic. */ QString comicAuthor() const override; /** * Returns additionalText of the comic. */ QString additionalText() const override; /** * Returns the name for the comic */ QString name() const override; /** * Returns whether the comic is leftToRight or not */ bool isLeftToRight() const override; /** * Returns whether the comic is topToBottom or not */ bool isTopToBottom() const override; /** * Returns whether a comic with the given @p identifier is cached. */ static bool isCached(const QString &identifier); /** * Map of keys and values to store in the config file for an individual identifier */ typedef QHash Settings; /** * Stores the given @p comic with the given @p identifier in the cache. */ static bool storeInCache(const QString &identifier, const QImage &comic, const Settings &info = Settings()); /** * Returns the website of the comic. */ QUrl websiteUrl() const override; QUrl imageUrl() const override; /** * Returns the shop website of the comic. */ QUrl shopUrl() const override; /** * Returns the maximum number of cached strips per comic, -1 means that there is no limit * @note defaulte is -1 */ static int maxComicLimit(); /** * Sets the maximum number of cached strips per comic, -1 means that there is no limit */ static void setMaxComicLimit(int limit); private Q_SLOTS: void triggerFinished(); private: static const int CACHE_DEFAULT; }; #endif diff --git a/dataengines/comic/comic.cpp b/dataengines/comic/comic.cpp index 5d4589d1b..03d89a348 100644 --- a/dataengines/comic/comic.cpp +++ b/dataengines/comic/comic.cpp @@ -1,328 +1,328 @@ /* * Copyright (C) 2007 Tobias Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "comic.h" #include #include #include #include #include #include #include #include #include #include "cachedprovider.h" #include "comicproviderkross.h" ComicEngine::ComicEngine(QObject* parent, const QVariantList& args) : Plasma::DataEngine(parent, args), mEmptySuffix(false) { setPollingInterval(0); loadProviders(); } ComicEngine::~ComicEngine() { } void ComicEngine::init() { connect(&m_networkConfigurationManager, &QNetworkConfigurationManager::onlineStateChanged, this, &ComicEngine::onOnlineStateChanged); } void ComicEngine::onOnlineStateChanged(bool isOnline) { if (isOnline && !mIdentifierError.isEmpty()) { sourceRequestEvent(mIdentifierError); } } void ComicEngine::loadProviders() { mProviders.clear(); removeAllData(QLatin1String("providers")); auto comics = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/Comic")); for (auto comic : comics) { mProviders << comic.pluginId(); //qDebug() << "ComicEngine::loadProviders() service name=" << comic.name(); QStringList data; data << comic.name(); QFileInfo file(comic.iconName()); if (file.isRelative()) { data << QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("plasma/comics/%1/%2").arg(comic.pluginId(), comic.iconName())); } else { data << comic.iconName(); } setData(QLatin1String("providers"), comic.pluginId(), data); } forceImmediateUpdateOfAllVisualizations(); } bool ComicEngine::updateSourceEvent(const QString &identifier) { if (identifier == QLatin1String("providers")) { loadProviders(); return true; } else if (identifier.startsWith(QLatin1String("setting_maxComicLimit:"))) { bool worked; const int maxComicLimit = identifier.mid(22).toInt(&worked); if (worked) { CachedProvider::setMaxComicLimit(maxComicLimit); } return worked; } else { if (m_jobs.contains(identifier)) { return true; } // check whether it is cached already... if (CachedProvider::isCached(identifier)) { QVariantList args; args << QLatin1String("String") << identifier; ComicProvider *provider = new CachedProvider(this, args); m_jobs[identifier] = provider; connect(provider, SIGNAL(finished(ComicProvider*)), this, SLOT(finished(ComicProvider*))); connect(provider, SIGNAL(error(ComicProvider*)), this, SLOT(error(ComicProvider*))); return true; } // ... start a new query otherwise const QStringList parts = identifier.split(QLatin1Char(':'), QString::KeepEmptyParts); //: are mandatory if (parts.count() < 2) { setData(identifier, QLatin1String("Error"), true); qWarning() << "Less than two arguments specified."; return false; } if (!mProviders.contains(parts[0])) { // User might have installed more from GHNS loadProviders(); if (!mProviders.contains(parts[0])) { setData(identifier, QLatin1String("Error"), true); qWarning() << identifier << "comic plugin does not seem to be installed."; return false; } } // check if there is a connection if (!m_networkConfigurationManager.isOnline()) { mIdentifierError = identifier; setData(identifier, QLatin1String("Error"), true); setData(identifier, QLatin1String("Error automatically fixable"), true); setData(identifier, QLatin1String("Identifier"), identifier); setData(identifier, QLatin1String("Previous identifier suffix"), lastCachedIdentifier(identifier)); qDebug() << "No connection."; return true; } KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Comic"), parts[0]); bool isCurrentComic = parts[1].isEmpty(); QVariantList args; ComicProvider *provider = nullptr; //const QString type = service->property(QLatin1String("X-KDE-PlasmaComicProvider-SuffixType"), QVariant::String).toString(); const QString type = pkg.metadata().value(QStringLiteral("X-KDE-PlasmaComicProvider-SuffixType")); if (type == QLatin1String("Date")) { QDate date = QDate::fromString(parts[1], Qt::ISODate); if (!date.isValid()) date = QDate::currentDate(); args << QLatin1String("Date") << date; } else if (type == QLatin1String("Number")) { args << QLatin1String("Number") << parts[1].toInt(); } else if (type == QLatin1String("String")) { args << QLatin1String("String") << parts[1]; } args << QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("plasma/comics/") + parts[0] + QLatin1String("/metadata.desktop")); //provider = service->createInstance(this, args); provider = new ComicProviderKross(this, args); if (!provider) { setData(identifier, QLatin1String("Error"), true); return false; } provider->setIsCurrent(isCurrentComic); m_jobs[identifier] = provider; connect(provider, SIGNAL(finished(ComicProvider*)), this, SLOT(finished(ComicProvider*))); connect(provider, SIGNAL(error(ComicProvider*)), this, SLOT(error(ComicProvider*))); return true; } } bool ComicEngine::sourceRequestEvent(const QString &identifier) { setData(identifier, DataEngine::Data()); return updateSourceEvent(identifier); } void ComicEngine::finished(ComicProvider *provider) { // sets the data setComicData(provider); if (provider->image().isNull()) { error(provider); return; } // different comic -- with no error yet -- has been chosen, old error is invalidated QString temp = mIdentifierError.left(mIdentifierError.indexOf(QLatin1Char(':')) + 1); if (!mIdentifierError.isEmpty() && provider->identifier().indexOf(temp) == -1) { mIdentifierError.clear(); } // comic strip with error worked now if (!mIdentifierError.isEmpty() && (mIdentifierError == provider->identifier())){ mIdentifierError.clear(); } // store in cache if it's not the response of a CachedProvider, // if there is a valid image and if there is a next comic // (if we're on today's comic it could become stale) if (!provider->inherits("CachedProvider") && !provider->image().isNull() && !provider->nextIdentifier().isEmpty()) { CachedProvider::Settings info; info[QLatin1String("websiteUrl")] = provider->websiteUrl().toString(QUrl::PrettyDecoded); info[QLatin1String("imageUrl")] = provider->imageUrl().url(); info[QLatin1String("shopUrl")] = provider->shopUrl().toString(QUrl::PrettyDecoded); info[QLatin1String("nextIdentifier")] = provider->nextIdentifier(); info[QLatin1String("previousIdentifier")] = provider->previousIdentifier(); info[QLatin1String("title")] = provider->name(); info[QLatin1String("suffixType")] = provider->suffixType(); info[QLatin1String("lastCachedStripIdentifier")] = provider->identifier().mid(provider->identifier().indexOf(QLatin1Char(':')) + 1); QString isLeftToRight; QString isTopToBottom; info[QLatin1String("isLeftToRight")] = isLeftToRight.setNum(provider->isLeftToRight()); info[QLatin1String("isTopToBottom")] = isTopToBottom.setNum(provider->isTopToBottom()); //data that should be only written if available if (!provider->comicAuthor().isEmpty()) { info[QLatin1String("comicAuthor")] = provider->comicAuthor(); } if (!provider->firstStripIdentifier().isEmpty()) { info[QLatin1String("firstStripIdentifier")] = provider->firstStripIdentifier(); } if (!provider->additionalText().isEmpty()) { info[QLatin1String("additionalText")] = provider->additionalText(); } if (!provider->stripTitle().isEmpty()) { info[QLatin1String("stripTitle")] = provider->stripTitle(); } CachedProvider::storeInCache(provider->identifier(), provider->image(), info); } provider->deleteLater(); const QString key = m_jobs.key(provider); if (!key.isEmpty()) { m_jobs.remove(key); } } void ComicEngine::error(ComicProvider *provider) { // sets the data setComicData(provider); QString identifier(provider->identifier()); mIdentifierError = identifier; - qWarning() << identifier << "pluging reported an error."; + qWarning() << identifier << "plugging reported an error."; /** * Requests for the current day have no suffix (date or id) * set initially, so we have to remove the 'faked' suffix * here again to not confuse the applet. */ if (provider->isCurrent()) identifier = identifier.left(identifier.indexOf(QLatin1Char(':')) + 1); setData(identifier, QLatin1String("Identifier"), identifier); setData(identifier, QLatin1String("Error"), true); // if there was an error loading the last cached comic strip, do not return its id anymore const QString lastCachedId = lastCachedIdentifier(identifier); if (lastCachedId != provider->identifier().mid(provider->identifier().indexOf(QLatin1Char(':')) + 1)) { // sets the previousIdentifier to the identifier of a strip that has been cached before setData(identifier, QLatin1String("Previous identifier suffix"), lastCachedId); } setData(identifier, QLatin1String("Next identifier suffix"), QString()); const QString key = m_jobs.key(provider); if (!key.isEmpty()) { m_jobs.remove(key); } provider->deleteLater(); } void ComicEngine::setComicData(ComicProvider *provider) { QString identifier(provider->identifier()); /** * Requests for the current day have no suffix (date or id) * set initially, so we have to remove the 'faked' suffix * here again to not confuse the applet. */ if (provider->isCurrent()) identifier = identifier.left(identifier.indexOf(QLatin1Char(':')) + 1); setData(identifier, QLatin1String("Image"), provider->image()); setData(identifier, QLatin1String("Website Url"), provider->websiteUrl()); setData(identifier, QLatin1String("Image Url"), provider->imageUrl()); setData(identifier, QLatin1String("Shop Url"), provider->shopUrl()); setData(identifier, QLatin1String("Next identifier suffix"), provider->nextIdentifier()); setData(identifier, QLatin1String("Previous identifier suffix"), provider->previousIdentifier()); setData(identifier, QLatin1String("Comic Author"), provider->comicAuthor()); setData(identifier, QLatin1String("Additional text"), provider->additionalText()); setData(identifier, QLatin1String("Strip title"), provider->stripTitle()); setData(identifier, QLatin1String("First strip identifier suffix"), provider->firstStripIdentifier()); setData(identifier, QLatin1String("Identifier"), provider->identifier()); setData(identifier, QLatin1String("Title"), provider->name()); setData(identifier, QLatin1String("SuffixType"), provider->suffixType()); setData(identifier, QLatin1String("isLeftToRight"), provider->isLeftToRight()); setData(identifier, QLatin1String("isTopToBottom"), provider->isTopToBottom()); setData(identifier, QLatin1String("Error"), false); } QString ComicEngine::lastCachedIdentifier(const QString &identifier) const { const QString id = identifier.left(identifier.indexOf(QLatin1Char(':'))); QString data = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/plasma_engine_comic/"); data += QString::fromLatin1(QUrl::toPercentEncoding(id)); QSettings settings(data + QLatin1String(".conf"), QSettings::IniFormat); QString previousIdentifier = settings.value(QLatin1String("lastCachedStripIdentifier"), QString()).toString(); return previousIdentifier; } K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(comic, ComicEngine, "plasma-dataengine-comic.json") #include "comic.moc" diff --git a/dataengines/comic/comic.h b/dataengines/comic/comic.h index 54ebcb05d..fb40c61a5 100644 --- a/dataengines/comic/comic.h +++ b/dataengines/comic/comic.h @@ -1,74 +1,74 @@ /* * Copyright (C) 2007 Tobias Koenig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef COMIC_DATAENGINE_H #define COMIC_DATAENGINE_H #include // Qt #include class ComicProvider; /** * This class provides the comic strip. * * The query keys have the following structure: - * : + * \:\ * usually the suffix is the date * e.g. * userfriendly:2007-07-19 * but some other comics uses numerical identifiers, like * xkcd:378 * if the suffix is empty the latest comic will be returned * */ class ComicEngine : public Plasma::DataEngine { Q_OBJECT public: ComicEngine(QObject* parent, const QVariantList& args); ~ComicEngine() override; public Q_SLOTS: void loadProviders(); protected: void init(); bool sourceRequestEvent(const QString &identifier) override; protected Q_SLOTS: bool updateSourceEvent(const QString &identifier) override; private Q_SLOTS: void finished(ComicProvider*); void error(ComicProvider*); void onOnlineStateChanged(bool); private: bool mEmptySuffix; void setComicData(ComicProvider *provider); QString lastCachedIdentifier(const QString &identifier) const; QString mIdentifierError; QStringList mProviders; QHash m_jobs; QNetworkConfigurationManager m_networkConfigurationManager; }; #endif diff --git a/dataengines/potd/apodprovider.h b/dataengines/potd/apodprovider.h index 09588ac8a..3cd83b122 100644 --- a/dataengines/potd/apodprovider.h +++ b/dataengines/potd/apodprovider.h @@ -1,73 +1,73 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef APODPROVIDER_H #define APODPROVIDER_H #include "potdprovider.h" #include class KJob; /** * This class provides the image for APOD * "Astronomy Picture Of the Day" * located at http://antwrp.gsfc.nasa.gov/apod. * Direct link to the picture of the day page is * http://antwrp.gsfc.nasa.gov/apod/apYYMMDD.html * where YY is the year last 2 digits, * MM is the month and DD the day, in 2 digits. */ class ApodProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new APOD provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ explicit ApodProvider( QObject *parent, const QVariantList &args ); /** * Destroys the APOD provider. */ ~ApodProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/bingprovider.h b/dataengines/potd/bingprovider.h index e9221550f..1678008d0 100644 --- a/dataengines/potd/bingprovider.h +++ b/dataengines/potd/bingprovider.h @@ -1,67 +1,67 @@ /* * Copyright 2017 Weng Xuetian * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef BINGPROVIDER_H #define BINGPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for the Bing's homepage * url is obtained from http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 */ class BingProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new Bing provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ BingProvider( QObject *parent, const QVariantList &args ); /** * Destroys the Bing provider. */ ~BingProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/epodprovider.h b/dataengines/potd/epodprovider.h index 4644e6a27..17e67d8bb 100644 --- a/dataengines/potd/epodprovider.h +++ b/dataengines/potd/epodprovider.h @@ -1,69 +1,69 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef EPODPROVIDER_H #define EPODPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for EPOD * "Earth Science Picture Of the Day" * located at http://epod.usra.edu/. */ class EpodProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new EPOD provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ EpodProvider( QObject *parent, const QVariantList &args ); /** * Destroys the EPOD provider. */ ~EpodProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/flickrprovider.h b/dataengines/potd/flickrprovider.h index de62edb55..316634db3 100644 --- a/dataengines/potd/flickrprovider.h +++ b/dataengines/potd/flickrprovider.h @@ -1,80 +1,80 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * Copyright 2008 by Georges Toth * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef FLICKRPROVIDER_H #define FLICKRPROVIDER_H #include "potdprovider.h" // Qt #include #include #include class KJob; /** * This class grabs a random image from the flickr * interestingness stream of pictures, for the given date. * Should there be no image for the current date, it tries * to grab one from the day before yesterday. */ class FlickrProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new flickr provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ explicit FlickrProvider( QObject *parent, const QVariantList &args ); /** * Destroys the flickr provider. */ ~FlickrProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QDate mActualDate; QImage mImage; QXmlStreamReader xml; int mFailureNumber = 0; QStringList m_photoList; }; #endif diff --git a/dataengines/potd/natgeoprovider.h b/dataengines/potd/natgeoprovider.h index 60dbbe743..b505770c7 100644 --- a/dataengines/potd/natgeoprovider.h +++ b/dataengines/potd/natgeoprovider.h @@ -1,77 +1,77 @@ /* * Copyright 2007 Tobias Koenig * Copyright 2008 Anne-Marie Mahfouf * Copyright 2013 Aaron Seigo * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef NATGEOPROVIDER_H #define NATGEOPROVIDER_H #include "potdprovider.h" // Qt #include #include class KJob; /** * This class provides the image for APOD * "Astronomy Picture Of the Day" * located at http://antwrp.gsfc.nasa.gov/apod. * Direct link to the picture of the day page is * http://antwrp.gsfc.nasa.gov/apod/apYYMMDD.html * where YY is the year last 2 digits, * MM is the month and DD the day, in 2 digits. */ class NatGeoProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new APOD provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ NatGeoProvider( QObject *parent, const QVariantList &args ); /** * Destroys the APOD provider. */ ~NatGeoProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; QRegularExpression re; }; #endif diff --git a/dataengines/potd/noaaprovider.h b/dataengines/potd/noaaprovider.h index 3af063065..75569b8b6 100644 --- a/dataengines/potd/noaaprovider.h +++ b/dataengines/potd/noaaprovider.h @@ -1,70 +1,70 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * Copyright 2016 Weng Xuetian * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef NOAAPROVIDER_H #define NOAAPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for NOAA Environmental Visualization Laboratory * Picture Of the Day * located at http://www.nnvl.noaa.gov/imageoftheday.php. */ class NOAAProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new NOAA provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ NOAAProvider( QObject *parent, const QVariantList &args ); /** * Destroys the NOAA provider. */ ~NOAAProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/dataengines/potd/potd.h b/dataengines/potd/potd.h index f261bd19d..9a0c65933 100644 --- a/dataengines/potd/potd.h +++ b/dataengines/potd/potd.h @@ -1,67 +1,67 @@ /* * Copyright (C) 2007 Tobias Koenig * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef POTD_DATAENGINE_H #define POTD_DATAENGINE_H #include #include class PotdProvider; class QTimer; /** * This class provides the Pictures of The Day from various online websites. * * The query keys have the following structure: - * : + * \:\ * e.g. * apod:2007-07-19 * */ class PotdEngine : public Plasma::DataEngine { Q_OBJECT public: PotdEngine( QObject* parent, const QVariantList& args ); ~PotdEngine() override; protected: bool sourceRequestEvent( const QString &identifier ) override; protected Q_SLOTS: bool updateSourceEvent( const QString &identifier ) override; private Q_SLOTS: void finished( PotdProvider* ); void error( PotdProvider* ); void checkDayChanged(); void cachingFinished( const QString &source, const QString &path, const QImage &img ); private: bool updateSource( const QString &identifier, bool loadCachedAlways ); QMap mFactories; QTimer *m_checkDatesTimer; bool m_canDiscardCache; }; #endif diff --git a/dataengines/potd/potdprovider.h b/dataengines/potd/potdprovider.h index 6a4ababe3..88e915a96 100644 --- a/dataengines/potd/potdprovider.h +++ b/dataengines/potd/potdprovider.h @@ -1,99 +1,100 @@ /* * Copyright (C) 2007 Tobias Koenig * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef POTDPROVIDER_H #define POTDPROVIDER_H #include #include #include "plasma_potd_export.h" class QImage; class QDate; /** * This class is an interface for PoTD providers. */ class PLASMA_POTD_EXPORT PotdProvider : public QObject { Q_OBJECT public: /** * Creates a new PoTD provider. * * @param parent The parent object. + * @param args The arguments. */ explicit PotdProvider(QObject *parent, const QVariantList &args = QVariantList()); /** * Destroys the PoTD provider. */ ~PotdProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ virtual QImage image() const = 0; /** * Returns the identifier of the PoTD request (name + date). */ virtual QString identifier() const; /** * @return the name of this provider (equiv to X-KDE-PlasmaPoTDProvider-Identifier) */ QString name() const; /** * @return the date to load for this item, if any */ QDate date() const; /** * @return if the date is fixed, or if it should always be "today" */ bool isFixedDate() const; Q_SIGNALS: /** * This signal is emitted whenever a request has been finished * successfully. * * @param provider The provider which emitted the signal. */ void finished( PotdProvider *provider ); /** * This signal is emitted whenever an error has occurred. * * @param provider The provider which emitted the signal. */ void error( PotdProvider *provider ); private: const QScopedPointer d; }; #endif diff --git a/dataengines/potd/wcpotdprovider.h b/dataengines/potd/wcpotdprovider.h index ee4d66298..e0403769c 100644 --- a/dataengines/potd/wcpotdprovider.h +++ b/dataengines/potd/wcpotdprovider.h @@ -1,72 +1,72 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * * This program is free 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 2 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef WCPOTDPROVIDER_H #define WCPOTDPROVIDER_H #include "potdprovider.h" // Qt #include class KJob; /** * This class provides the image for the "Wikimedia * Commons Picture Of the Day" * located at http://tools.wikimedia.de/~daniel/potd/commons/potd-800x600.html. * From there extract the picture. * Using 800x600 as the best size for now, others are available, see * http://tools.wikimedia.de/~daniel/potd/potd.php */ class WcpotdProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new Wcpotd provider. * - * @param date The date for which the image shall be fetched. * @param parent The parent object. + * @param args The arguments. */ WcpotdProvider( QObject *parent, const QVariantList &args ); /** * Destroys the Wcpotd provider. */ ~WcpotdProvider() override; /** * Returns the requested image. * * Note: This method returns only a valid image after the * finished() signal has been emitted. */ QImage image() const override; private: void pageRequestFinished(KJob *job); void imageRequestFinished(KJob *job); private: QImage mImage; }; #endif diff --git a/runners/characters/charrunner.cpp b/runners/characters/charrunner.cpp index e7083c353..5b4969d64 100644 --- a/runners/characters/charrunner.cpp +++ b/runners/characters/charrunner.cpp @@ -1,101 +1,101 @@ /* Copyright 2010 Anton Kreuzkamp * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "charrunner.h" // KF #include #include //Names of config-entries static const char CONFIG_TRIGGERWORD[] = "triggerWord"; static const char CONFIG_ALIASES[] = "aliases"; static const char CONFIG_CODES[] = "codes"; CharacterRunner::CharacterRunner( QObject* parent, const QVariantList &args ) : Plasma::AbstractRunner(parent, args) { Q_UNUSED(args) setObjectName(QLatin1String( "CharacterRunner" )); setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File | Plasma::RunnerContext::NetworkLocation | Plasma::RunnerContext::Executable | Plasma::RunnerContext::ShellCommand); reloadConfiguration(); } CharacterRunner::~CharacterRunner() { } void CharacterRunner::reloadConfiguration() { KConfigGroup grp = config(); //Create config-object m_triggerWord = grp.readEntry(CONFIG_TRIGGERWORD, "#"); //read out the triggerword m_aliases = grp.readEntry(CONFIG_ALIASES, QStringList()); m_codes = grp.readEntry(CONFIG_CODES, QStringList()); addSyntax(Plasma::RunnerSyntax(m_triggerWord + QLatin1String( ":q:" ), i18n("Creates Characters from :q: if it is a hexadecimal code or defined alias."))); } void CharacterRunner::match(Plasma::RunnerContext &context) { QString term = context.query(); term = term.replace(QLatin1Char( ' ' ), QLatin1String( "" )); //remove blanks if (term.length() < 2) //ignore too short queries { return; } if (!term.startsWith(m_triggerWord)) //ignore queries without the triggerword { return; } term = term.remove(0, m_triggerWord.length()); //remove the triggerword if (m_aliases.contains(term)) //replace aliases by their hex.-code { term = m_codes[m_aliases.indexOf(term)]; } bool ok; //checkvariable int hex = term.toInt(&ok, 16); //convert query into int if (!ok) //check if conversion was successful { return; } - //make special caracter out of the hex.-code + //make special character out of the hex.-code const QString specChar = QChar(hex); //create match Plasma::QueryMatch match(this); match.setType(Plasma::QueryMatch::InformationalMatch); match.setIconName(QStringLiteral("accessories-character-map")); match.setText(specChar); match.setData(specChar); match.setId(QString()); context.addMatch(match); } K_EXPORT_PLASMA_RUNNER(CharacterRunner, CharacterRunner) #include "charrunner.moc" diff --git a/runners/datetime/datetimerunner.h b/runners/datetime/datetimerunner.h index af5a268c3..80ceda518 100644 --- a/runners/datetime/datetimerunner.h +++ b/runners/datetime/datetimerunner.h @@ -1,51 +1,51 @@ /* * Copyright (C) 2010 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef DATETIMERUNNER_H #define DATETIMERUNNER_H #include #include #include /** * This class looks for matches in the set of .desktop files installed by * applications. This way the user can type exactly what they see in the - * appications menu and have it start the appropriate app. Essentially anything + * applications menu and have it start the appropriate app. Essentially anything * that KService knows about, this runner can launch */ class DateTimeRunner : public Plasma::AbstractRunner { Q_OBJECT public: DateTimeRunner(QObject *parent, const QVariantList &args); ~DateTimeRunner() override; void match(Plasma::RunnerContext &context) override; private: QHash datetime(const QStringRef &tz); void addMatch(const QString &text, const QString &clipboardText, Plasma::RunnerContext &context, const QString& iconName); }; #endif