[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/kcontrol/keys
From:       Michael Jansen <kde () michael-jansen ! biz>
Date:       2008-02-29 23:48:22
Message-ID: 1204328902.338811.21564.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 780782 by mjansen:

First shot at importing / exporting Shortcut Configuration. Also known as schemes. 

  - Barely working. Use on your own risk
  - SelectSchemeDialog is my first. Please help me improve
  - The added kksrc files are from kde3. They work only in half because some \
Shortcuts have changed their name. Bad selection for a id.


 M  +22 -8     CMakeLists.txt  
 M  +88 -15    globalshortcuts.cpp  
 M  +5 -0      globalshortcuts.h  
 A             kde3.kksrc  
 A             kde4.kksrc  
 M  +34 -1     kglobalshortcutseditor.cpp  
 M  +25 -7     kglobalshortcutseditor.h  
 A             mac4.kksrc  
 A             schemes (directory)  
 A             schemes/kde3.kksrc  
 A             schemes/kde4.kksrc  
 A             schemes/mac4.kksrc  
 A             schemes/test.kksrc  
 A             schemes/unix3.kksrc  
 A             schemes/win3.kksrc  
 A             schemes/win4.kksrc  
 A             schemes/wm3.kksrc  
 A             select_scheme_dialog.cpp   [License: GPL (v2+)]
 A             select_scheme_dialog.h   [License: GPL (v2+)]
 A             select_scheme_dialog.ui  
 A             unix3.kksrc  
 A             win3.kksrc  
 A             win4.kksrc  
 A             wm3.kksrc  


--- trunk/KDE/kdebase/workspace/kcontrol/keys/CMakeLists.txt #780781:780782
@@ -1,17 +1,19 @@
-
-
 ########### next target ###############
 
-set(kcm_keys_PART_SRCS 
-   kglobalshortcutseditor.cpp
-   globalshortcuts.cpp )
+set(kcm_keys_PART_SRCS
+  kglobalshortcutseditor.cpp
+  globalshortcuts.cpp
+  select_scheme_dialog.cpp
+  )
 
-kde4_add_ui_files( kcm_keys_PART_SRCS kglobalshortcutseditor.ui )
+kde4_add_ui_files( kcm_keys_PART_SRCS 
+    kglobalshortcutseditor.ui
+    select_scheme_dialog.ui )
 
 kde4_add_plugin(kcm_keys ${kcm_keys_PART_SRCS})
 
 
-target_link_libraries(kcm_keys  ${KDE4_KDEUI_LIBS} ${X11_X11_LIB})
+target_link_libraries(kcm_keys  ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} \
${KDE4_KFILE_LIBS} ${X11_X11_LIB})  
 install(TARGETS kcm_keys  DESTINATION ${PLUGIN_INSTALL_DIR} )
 
@@ -19,7 +21,19 @@
 ########### install files ###############
 
 install( FILES keys.desktop  DESTINATION  ${SERVICES_INSTALL_DIR} )
-# install( FILES wm3.kksrc kde3.kksrc kde4.kksrc win3.kksrc win4.kksrc mac4.kksrc \
unix3.kksrc  DESTINATION  ${DATA_INSTALL_DIR}/kcmkeys ) +install( FILES
+    kde3.kksrc
+    kde4.kksrc
+    mac4.kksrc
+    test.kksrc
+    unix3.kksrc
+    win3.kksrc
+    win4.kksrc
+    wm3.kksrc
+    DESTINATION  ${DATA_INSTALL_DIR}/kcmkeys )
+
+
+
 install( FILES kaccel.upd  DESTINATION  ${KCONF_UPDATE_INSTALL_DIR} )
 install(PROGRAMS convertShortcuts.pl  DESTINATION  ${KCONF_UPDATE_INSTALL_DIR} )
 
--- trunk/KDE/kdebase/workspace/kcontrol/keys/globalshortcuts.cpp #780781:780782
@@ -1,5 +1,6 @@
 /*
  *  Copyright 2007 Andreas Pakulat <apaku@gmx.de>
+ *  Copyright 2008 Michael Jansen <kde@michael-jansen.biz>
  *
  *  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
@@ -16,22 +17,27 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 #include "globalshortcuts.h"
+#include "kglobalshortcutseditor.h"
+#include "select_scheme_dialog.h"
+#include <kdebug.h>
 
 #include <QDBusConnection>
 #include <QDBusInterface>
 #include <QDBusReply>
 #include <QDBusMetaType>
-#include <QMetaType>
-#include <QVBoxLayout>
+#include <QLayout>
 #include <QPointer>
 
-#include <kpluginfactory.h>
-#include <kactioncollection.h>
-#include <kaction.h>
-#include <kglobalshortcutseditor.h>
-#include <kdebug.h>
-#include <qcombobox.h>
-#include <kglobalaccel.h>
+#include <KAction>
+#include <KActionCollection>
+#include <KConfig>
+#include <KConfigGroup>
+#include <KDirSelectDialog>
+#include <KGlobalAccel>
+#include <KLocale>
+#include <KMessageBox>
+#include <KPluginFactory>
+#include <KPushButton>
 
 K_PLUGIN_FACTORY(GlobalShortcutsModuleFactory, \
registerPlugin<GlobalShortcutsModule>();)  \
K_EXPORT_PLUGIN(GlobalShortcutsModuleFactory("kcmkeys")) @@ -43,10 +49,37 @@
       editor(0)
 {
     KCModule::setButtons( KCModule::Buttons(KCModule::Default|KCModule::Apply) );
+
+    // Add import scheme button
+    KPushButton *importButton = new KPushButton(this);
+    importButton->setText(i18n("Import scheme ..."));
+    connect( 
+        importButton, SIGNAL(clicked()),
+        this,SLOT(importScheme()) );
+
+    // Add export scheme button
+    KPushButton *exportButton = new KPushButton(this);
+    exportButton->setText(i18n("Export scheme ..."));
+    connect( 
+        exportButton, SIGNAL(clicked()),
+        this,SLOT(exportScheme()) );
+
+    // Layout for the buttons
+    QHBoxLayout *hbox = new QHBoxLayout;
+    hbox->addWidget(exportButton);
+    hbox->addWidget(importButton);
+
+    // Create the kglobaleditor
     editor = new KGlobalShortcutsEditor(this, KShortcutsEditor::GlobalAction);
-    setLayout( new QVBoxLayout );
-    layout()->addWidget(editor);
-    connect(editor, SIGNAL(changed()), this, SLOT(changed()) );
+    connect(editor, SIGNAL(changed(bool)), this, SIGNAL(changed(bool)) );
+
+    // Layout the hole bunch
+    QVBoxLayout *global = new QVBoxLayout;
+    global->addLayout(hbox);
+    global->addWidget(editor);
+    setLayout(global);
+
+    // Initialize our content
     load();
 }
 
@@ -77,9 +110,9 @@
         QDBusReply<QStringList> actions = iface->call("allActionsForComponent", \
qVariantFromValue(component) );  foreach(const QString &actionText, actions.value() )
         {
-            // kDebug() << "- action:" << actionText;
-            QString actionName = QString("%1_%2").arg(component).arg(col->count());
-            KAction *action = col->addAction(actionName);
+            kWarning() << "FIXME: Get a real objectName from iface!";
+            QString objectName = actionText;
+            KAction *action = col->addAction(objectName);
             // see KAction::~KAction
             action->setProperty("isConfigurationAction", QVariant(true));
             action->setText(actionText);
@@ -122,4 +155,44 @@
     editor->save();
 }
 
+
+void GlobalShortcutsModule::importScheme()
+{
+    // Check for unsaved modifications
+    if (editor->isModified()) {
+        int choice = KMessageBox::warningContinueCancel(
+            parentWidget(),
+            i18n("Your current changes will be lost if you load another scheme \
before saving this one"), +            i18n("Load shortcurt scheme"),
+            KGuiItem(i18n("Load")) );
+        if (choice != KMessageBox::Continue)
+            {
+            return;
+            }
+    }
+
+    SelectSchemeDialog dialog(this);
+    if (dialog.exec() != KDialog::Accepted) {
+        return;
+    }
+
+    KUrl url = dialog.selectedScheme();
+    Q_ASSERT(url.isLocalFile());
+    kDebug() << url.path();
+    KConfig config(url.path());
+    editor->importConfiguration(&config);
+}
+
+
+void GlobalShortcutsModule::exportScheme()
+{
+    KUrl url = KDirSelectDialog::selectDirectory( KUrl(), true, parentWidget() );
+    if (!url.isEmpty()) {
+        KConfig config(url.path());
+        config.deleteGroup( "Shortcuts" );
+        config.deleteGroup( "Global Shortcuts" );
+        editor->exportConfiguration(&config);
+    }
+}
+
 #include "globalshortcuts.moc"
--- trunk/KDE/kdebase/workspace/kcontrol/keys/globalshortcuts.h #780781:780782
@@ -1,5 +1,6 @@
 /*
  * Copyright 2007 Andreas Pakulat <apaku@gmx.de>
+ * Copyright 2008 Michael Jansen <kde@michael-jansen.biz>
  *
  *  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
@@ -35,6 +36,10 @@
     virtual void save();
     virtual void load();
     virtual void defaults();
+
+public slots:
+    virtual void importScheme();
+    virtual void exportScheme();
 private:
     KGlobalShortcutsEditor *editor;
 };
--- trunk/KDE/kdebase/workspace/kcontrol/keys/kglobalshortcutseditor.cpp \
#780781:780782 @@ -178,6 +178,7 @@
     }
 
 
+
 void KGlobalShortcutsEditor::save()
     {
     // The editors are responsible for the saving
@@ -189,6 +190,25 @@
     }
 
 
+void KGlobalShortcutsEditor::importConfiguration( KConfig *config )
+    {
+    // The editors are responsible for the writing of the scheme
+    Q_FOREACH (KShortcutsEditor *editor, d->components.values())
+        {
+        editor->importConfiguration(config);
+        }
+    }
+
+void KGlobalShortcutsEditor::exportConfiguration( KConfig *config ) const
+    {
+    // The editors are responsible for the writing of the scheme
+    Q_FOREACH (KShortcutsEditor *editor, d->components.values())
+        {
+        editor->exportConfiguration(config);
+        }
+    }
+
+
 void KGlobalShortcutsEditor::undo()
     {
     // The editors are responsible for the undo
@@ -200,9 +220,22 @@
     }
 
 
+bool KGlobalShortcutsEditor::isModified() const
+    {
+    Q_FOREACH (KShortcutsEditor *editor, d->components.values())
+        {
+        if (editor->isModified()) 
+            {
+            return true;
+            }
+        }
+    return false;
+    }
+
+
 void KGlobalShortcutsEditor::_k_key_changed()
     {
-    changed();
+    emit changed(isModified());
     }
 
 #include "kglobalshortcutseditor.moc"
--- trunk/KDE/kdebase/workspace/kcontrol/keys/kglobalshortcutseditor.h #780781:780782
@@ -24,6 +24,7 @@
 
 class KActionCollection;
 class KShortcut;
+class KConfig;
 
 /**
  * Combine a KShortcutsEditor with a KComboBox.
@@ -56,25 +57,42 @@
         void addCollection( KActionCollection *, const QString &component, const \
QString &title = QString() );  
         /**
+         * Clear all collections were currently hosting.
+         */
+        void clear();
+
+
+        /**
          * Revert all changes made since the last save.
          */
         void undo();
 
+
         /**
-         * Clear all collections were currently hosting.
+         * Load the shortcuts from the configuration.
          */
-        void clear();
+        void importConfiguration( KConfig *config );
 
+
+        /**
+         * Save the shortcuts to the configuration.
+         */
+        void exportConfiguration( KConfig *config ) const;
+
+
+        /**
+         * Are the unsaved changes?
+         */
+        bool isModified() const;
+
     Q_SIGNALS:
 
         /**
          * Indicate that state of the modules contents has changed.
          *
-         * There is currently no way to tell if the contents is really changed :-( .
-         *
-         * @param state changes or not
+         * @param state changed or not
          */
-        void changed();
+        void changed(bool);
 
 
     public Q_SLOTS:
@@ -106,7 +124,7 @@
 
     private:
 
-	    friend class KGlobalShortcutsEditorPrivate;
+        friend class KGlobalShortcutsEditorPrivate;
         class KGlobalShortcutsEditorPrivate;
         KGlobalShortcutsEditorPrivate *const d;
         Q_DISABLE_COPY(KGlobalShortcutsEditor)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic