]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinremoteencoding.cpp
DolphinStatusbar: Fix background and margins for non-Breeze styles
[dolphin.git] / src / views / dolphinremoteencoding.cpp
index 6de5e3e93e69125a19630b222494acf91684a02a..33c5868d660df6df55beae52a4b80c1d3d1617b8 100644 (file)
@@ -1,61 +1,47 @@
-/***************************************************************************
- *   Copyright (C) 2009 by Rahman Duran <rahman.duran@gmail.com>           *
- *                                                                         *
- *   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            *
- ***************************************************************************/
-
- /*
+/*
+ * SPDX-FileCopyrightText: 2009 Rahman Duran <rahman.duran@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/*
  * This code is largely based on the kremoteencodingplugin
- * Copyright (c) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
+ * SPDX-FileCopyrightText: 2003 Thiago Macieira <thiago.macieira@kdemail.net>
  * Distributed under the same terms.
  */
 
 #include "dolphinremoteencoding.h"
+
+#include "dolphindebug.h"
 #include "dolphinviewactionhandler.h"
 
-#include <KDebug>
-#include <KActionMenu>
 #include <KActionCollection>
-#include <KIcon>
-#include <KLocale>
-#include <KGlobal>
-#include <KMimeType>
-#include <KConfig>
+#include <KActionMenu>
 #include <KCharsets>
-#include <KMenu>
+#include <KConfig>
+#include <KConfigGroup>
+#include <KLocalizedString>
 #include <KProtocolInfo>
 #include <KProtocolManager>
-#include <KIO/Scheduler>
-#include <KConfigGroup>
 
-#define DATA_KEY        QLatin1String("Charset")
+#include <QDBusConnection>
+#include <QDBusMessage>
+#include <QMenu>
 
-DolphinRemoteEncoding::DolphinRemoteEncoding(QObject* parent, DolphinViewActionHandler* actionHandler)
-   :QObject(parent),
-    m_actionHandler(actionHandler),
-    m_loaded(false),
-    m_idDefault(0)
+#define DATA_KEY QStringLiteral("Charset")
+
+DolphinRemoteEncoding::DolphinRemoteEncoding(QObject *parent, DolphinViewActionHandler *actionHandler)
+    : QObject(parent)
+    , m_actionHandler(actionHandler)
+    , m_loaded(false)
+    , m_idDefault(0)
 {
-    m_menu = new KActionMenu(KIcon("character-set"), i18n("Select Remote Charset"), this);
-    m_actionHandler->actionCollection()->addAction("change_remote_encoding", m_menu);
-    connect(m_menu->menu(), SIGNAL(aboutToShow()),
-          this, SLOT(slotAboutToShow()));
+    m_menu = new KActionMenu(QIcon::fromTheme(QStringLiteral("character-set")), i18n("Select Remote Charset"), this);
+    m_actionHandler->actionCollection()->addAction(QStringLiteral("change_remote_encoding"), m_menu);
+    connect(m_menu->menu(), &QMenu::aboutToShow, this, &DolphinRemoteEncoding::slotAboutToShow);
 
     m_menu->setEnabled(false);
-    m_menu->setDelayed(false);
+    m_menu->setPopupMode(QToolButton::InstantPopup);
 }
 
 DolphinRemoteEncoding::~DolphinRemoteEncoding()
@@ -70,22 +56,20 @@ void DolphinRemoteEncoding::slotReload()
 void DolphinRemoteEncoding::loadSettings()
 {
     m_loaded = true;
-    m_encodingDescriptions = KGlobal::charsets()->descriptiveEncodingNames();
+    m_encodingDescriptions = KCharsets::charsets()->descriptiveEncodingNames();
 
     fillMenu();
 }
 
 void DolphinRemoteEncoding::slotAboutToOpenUrl()
 {
-    KUrl oldURL = m_currentURL;
+    QUrl oldURL = m_currentURL;
     m_currentURL = m_actionHandler->currentView()->url();
 
-    if (m_currentURL.protocol() != oldURL.protocol()) {
+    if (m_currentURL.scheme() != oldURL.scheme()) {
         // This plugin works on ftp, fish, etc.
         // everything whose type is T_FILESYSTEM except for local files
-        if (!m_currentURL.isLocalFile() &&
-            KProtocolManager::outputType(m_currentURL) == KProtocolInfo::T_FILESYSTEM) {
-
+        if (!m_currentURL.isLocalFile() && KProtocolManager::outputType(m_currentURL) == KProtocolInfo::T_FILESYSTEM) {
             m_menu->setEnabled(true);
             loadSettings();
         } else {
@@ -101,23 +85,22 @@ void DolphinRemoteEncoding::slotAboutToOpenUrl()
 
 void DolphinRemoteEncoding::fillMenu()
 {
-    QMenumenu = m_menu->menu();
+    QMenu *menu = m_menu->menu();
     menu->clear();
 
-
-    for (int i = 0; i < m_encodingDescriptions.size();i++) {
-        QActionaction = new QAction(m_encodingDescriptions.at(i), this);
+    menu->addAction(i18n("Default"), this, &DolphinRemoteEncoding::slotDefault)->setCheckable(true);
+    for (int i = 0; i < m_encodingDescriptions.size(); i++) {
+        QAction *action = new QAction(m_encodingDescriptions.at(i), this);
         action->setCheckable(true);
         action->setData(i);
         menu->addAction(action);
     }
     menu->addSeparator();
 
-    menu->addAction(i18n("Reload"), this, SLOT(slotReload()), 0);
-    menu->addAction(i18n("Default"), this, SLOT(slotDefault()), 0)->setCheckable(true);
+    menu->addAction(i18n("Reload"), this, &DolphinRemoteEncoding::slotReload);
     m_idDefault = m_encodingDescriptions.size() + 2;
 
-    connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(slotItemSelected(QAction*)));
+    connect(menu, &QMenu::triggered, this, &DolphinRemoteEncoding::slotItemSelected);
 }
 
 void DolphinRemoteEncoding::updateMenu()
@@ -127,11 +110,11 @@ void DolphinRemoteEncoding::updateMenu()
     }
 
     // uncheck everything
-    for (int i =  0; i < m_menu->menu()->actions().count(); i++) {
+    for (int i = 0; i < m_menu->menu()->actions().count(); i++) {
         m_menu->menu()->actions().at(i)->setChecked(false);
     }
 
-    const QString charset = KGlobal::charsets()->descriptionForEncoding(KProtocolManager::charsetFor(m_currentURL));
+    const QString charset = KCharsets::charsets()->descriptionForEncoding(KProtocolManager::charsetFor(m_currentURL));
     if (!charset.isEmpty()) {
         int id = 0;
         bool isFound = false;
@@ -143,17 +126,16 @@ void DolphinRemoteEncoding::updateMenu()
             }
         }
 
-        kDebug() << "URL=" << m_currentURL << " charset=" << charset;
+        qCDebug(DolphinDebug) << "URL=" << m_currentURL << " charset=" << charset;
 
         if (!isFound) {
-            kWarning() << "could not find entry for charset=" << charset ;
+            qCWarning(DolphinDebug) << "could not find entry for charset=" << charset;
         } else {
             m_menu->menu()->actions().at(id)->setChecked(true);
         }
     } else {
         m_menu->menu()->actions().at(m_idDefault)->setChecked(true);
     }
-
 }
 
 void DolphinRemoteEncoding::slotAboutToShow()
@@ -164,15 +146,15 @@ void DolphinRemoteEncoding::slotAboutToShow()
     updateMenu();
 }
 
-void DolphinRemoteEncoding::slotItemSelected(QActionaction)
+void DolphinRemoteEncoding::slotItemSelected(QAction *action)
 {
     if (action) {
         int id = action->data().toInt();
 
-        KConfig config(("kio_" + m_currentURL.protocol() + "rc").toLatin1());
+        KConfig config(QLatin1String("kio_%1rc").arg(m_currentURL.scheme()));
         QString host = m_currentURL.host();
         if (m_menu->menu()->actions().at(id)->isChecked()) {
-            QString charset = KGlobal::charsets()->encodingForName(m_encodingDescriptions.at(id));
+            QString charset = KCharsets::charsets()->encodingForName(m_encodingDescriptions.at(id));
             KConfigGroup cg(&config, host);
             cg.writeEntry(DATA_KEY, charset);
             config.sync();
@@ -187,9 +169,9 @@ void DolphinRemoteEncoding::slotDefault()
 {
     // We have no choice but delete all higher domain level
     // settings here since it affects what will be matched.
-    KConfig config(("kio_" + m_currentURL.protocol() + "rc").toLatin1());
+    KConfig config(QLatin1String("kio_%1rc").arg(m_currentURL.scheme()));
 
-    QStringList partList = m_currentURL.host().split('.', QString::SkipEmptyParts);
+    QStringList partList = m_currentURL.host().split(QLatin1Char('.'), Qt::SkipEmptyParts);
     if (!partList.isEmpty()) {
         partList.erase(partList.begin());
 
@@ -208,16 +190,16 @@ void DolphinRemoteEncoding::slotDefault()
                 break;
             }
 
-            domains << partList.join(".");
+            domains << partList.join(QLatin1Char('.'));
             partList.erase(partList.begin());
         }
 
-        for (QStringList::const_iterator it = domains.constBegin(); it != domains.constEnd();++it) {
-            kDebug() << "Domain to remove: " << *it;
+        for (QStringList::const_iterator it = domains.constBegin(); it != domains.constEnd(); ++it) {
+            qCDebug(DolphinDebug) << "Domain to remove: " << *it;
             if (config.hasGroup(*it)) {
                 config.deleteGroup(*it);
-            } else if (config.group("").hasKey(*it)) {
-                config.group("").deleteEntry(*it); //don't know what group name is supposed to be XXX
+            } else if (config.group(QString()).hasKey(*it)) {
+                config.group(QString()).deleteEntry(*it); // don't know what group name is supposed to be XXX
             }
         }
     }
@@ -229,10 +211,14 @@ void DolphinRemoteEncoding::slotDefault()
 
 void DolphinRemoteEncoding::updateView()
 {
-    KIO::Scheduler::emitReparseSlaveConfiguration();
+    QDBusMessage message =
+        QDBusMessage::createSignal(QStringLiteral("/KIO/Scheduler"), QStringLiteral("org.kde.KIO.Scheduler"), QStringLiteral("reparseSlaveConfiguration"));
+    message << QString();
+    QDBusConnection::sessionBus().send(message);
+
     // Reload the page with the new charset
     m_actionHandler->currentView()->setUrl(m_currentURL);
     m_actionHandler->currentView()->reload();
 }
 
-#include "dolphinremoteencoding.moc"
+#include "moc_dolphinremoteencoding.cpp"