]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinremoteencoding.cpp
Merge branch 'master' into frameworks
[dolphin.git] / src / views / dolphinremoteencoding.cpp
index 397eaccc098babbe5819ca3b81c78ce345b93af0..ceb189494a5f9ddd0b66011e296c659b25495747 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
+
  /*
  * This code is largely based on the kremoteencodingplugin
  * Copyright (c) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
  * Distributed under the same terms.
  */
+
 #include "dolphinremoteencoding.h"
 #include "dolphinviewactionhandler.h"
 
-#include <kdebug.h>
-#include <kactionmenu.h>
-#include <kactioncollection.h>
-#include <kicon.h>
-#include <klocale.h>
-#include <kglobal.h>
-#include <kmimetype.h>
-#include <kconfig.h>
-#include <kcharsets.h>
-#include <kmenu.h>
-#include <kprotocolinfo.h>
-#include <kprotocolmanager.h>
-#include <kio/slaveconfig.h>
-#include <kio/scheduler.h>
-#include <kconfiggroup.h>
+#include <KDebug>
+#include <KActionMenu>
+#include <KActionCollection>
+#include <KIcon>
+#include <KLocale>
+#include <KGlobal>
+#include <KMimeType>
+#include <KConfig>
+#include <KCharsets>
+#include <KMenu>
+#include <KProtocolInfo>
+#include <KProtocolManager>
+#include <KIO/Scheduler>
+#include <KConfigGroup>
 
 #define DATA_KEY        QLatin1String("Charset")
 
@@ -48,12 +47,12 @@ DolphinRemoteEncoding::DolphinRemoteEncoding(QObject* parent, DolphinViewActionH
    :QObject(parent),
     m_actionHandler(actionHandler),
     m_loaded(false),
-    m_idDefault(0)    
+    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()));
+    connect(m_menu->menu(), &QMenu::aboutToShow,
+          this, &DolphinRemoteEncoding::slotAboutToShow);
 
     m_menu->setEnabled(false);
     m_menu->setDelayed(false);
@@ -86,7 +85,7 @@ void DolphinRemoteEncoding::slotAboutToOpenUrl()
         // everything whose type is T_FILESYSTEM except for local files
         if (!m_currentURL.isLocalFile() &&
             KProtocolManager::outputType(m_currentURL) == KProtocolInfo::T_FILESYSTEM) {
-          
+
             m_menu->setEnabled(true);
             loadSettings();
         } else {
@@ -102,10 +101,10 @@ void DolphinRemoteEncoding::slotAboutToOpenUrl()
 
 void DolphinRemoteEncoding::fillMenu()
 {
-    KMenu* menu = m_menu->menu();
+    QMenu* menu = m_menu->menu();
     menu->clear();
 
+
     for (int i = 0; i < m_encodingDescriptions.size();i++) {
         QAction* action = new QAction(m_encodingDescriptions.at(i), this);
         action->setCheckable(true);
@@ -117,8 +116,8 @@ void DolphinRemoteEncoding::fillMenu()
     menu->addAction(i18n("Reload"), this, SLOT(slotReload()), 0);
     menu->addAction(i18n("Default"), this, SLOT(slotDefault()), 0)->setCheckable(true);
     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()
@@ -126,26 +125,24 @@ void DolphinRemoteEncoding::updateMenu()
     if (!m_loaded) {
         loadSettings();
     }
-  
+
     // uncheck everything
     for (int i =  0; i < m_menu->menu()->actions().count(); i++) {
         m_menu->menu()->actions().at(i)->setChecked(false);
     }
-  
-    QString charset = KIO::SlaveConfig::self()->configData(m_currentURL.protocol(),
-                                                           m_currentURL.host(), DATA_KEY);
 
+    const QString charset = KGlobal::charsets()->descriptionForEncoding(KProtocolManager::charsetFor(m_currentURL));
     if (!charset.isEmpty()) {
         int id = 0;
         bool isFound = false;
         for (int i = 0; i < m_encodingDescriptions.size(); i++) {
-            if (m_encodingDescriptions.at(i).contains(charset)) {
+            if (m_encodingDescriptions.at(i) == charset) {
                 isFound = true;
                 id = i;
                 break;
             }
         }
-      
+
         kDebug() << "URL=" << m_currentURL << " charset=" << charset;
 
         if (!isFound) {
@@ -156,7 +153,7 @@ void DolphinRemoteEncoding::updateMenu()
     } else {
         m_menu->menu()->actions().at(m_idDefault)->setChecked(true);
     }
-    
+
 }
 
 void DolphinRemoteEncoding::slotAboutToShow()
@@ -169,9 +166,9 @@ void DolphinRemoteEncoding::slotAboutToShow()
 
 void DolphinRemoteEncoding::slotItemSelected(QAction* action)
 {
-    if (action != 0) {
+    if (action) {
         int id = action->data().toInt();
-    
+
         KConfig config(("kio_" + m_currentURL.protocol() + "rc").toLatin1());
         QString host = m_currentURL.host();
         if (m_menu->menu()->actions().at(id)->isChecked()) {
@@ -200,7 +197,7 @@ void DolphinRemoteEncoding::slotDefault()
         // Remove the exact name match...
         domains << m_currentURL.host();
 
-        while (partList.count()) {
+        while (!partList.isEmpty()) {
             if (partList.count() == 2) {
                 if (partList[0].length() <= 2 && partList[1].length() == 2) {
                     break;
@@ -238,4 +235,3 @@ void DolphinRemoteEncoding::updateView()
     m_actionHandler->currentView()->reload();
 }
 
-#include "dolphinremoteencoding.moc"