29
36
static const char* FILE_FILTER = I18N_NOOP("*.keymap|Krusader keymaps\n*|all files");
32
KrKeyDialog::KrKeyDialog( QWidget * parent ) : KShortcutsDialog( KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed /* allow letter shortcuts */, parent ) {
33
addCollection( krApp->actionCollection() );
35
// HACK This fetches the layout of the buttonbox from KDialog, although it is not accessable with KDialog's API
36
// None the less it's quite save to use since this implementation hasn't changed since KDE-3.3 (I haven't looked at earlier
37
// versions since we don't support them) and now all work is done in KDE-4.
38
QWidget* buttonBox = static_cast<QWidget*>( button(KDialog::Ok)->parent() );
39
QBoxLayout* buttonBoxLayout = static_cast<QBoxLayout*>( buttonBox->layout() );
41
KPushButton* importButton = new KPushButton( i18n("Import shortcuts"), buttonBox );
42
importButton->setWhatsThis( i18n( "Load a keybinding profile, e.g., total_commander.keymap" ) );
43
buttonBoxLayout->insertWidget( 1, importButton ); // the defaults-button should stay on position 0
44
connect( importButton, SIGNAL( clicked() ), SLOT( slotImportShortcuts() ) );
46
KPushButton* exportButton = new KPushButton( i18n("Export shortcuts"), buttonBox );
47
exportButton->setWhatsThis( i18n( "Save current keybindings in a keymap file." ) );
48
buttonBoxLayout->insertWidget( 2, exportButton );
49
connect( exportButton, SIGNAL( clicked() ), SLOT( slotExportShortcuts() ) );
51
// Also quite HACK 'isch but unfortunately KKeyDialog don't giveus access to this widget
52
_chooser = static_cast<KShortcutsEditor*>( mainWidget() );
54
configure( true /* SaveSettings */ ); // this runs the dialog
57
KrKeyDialog::~KrKeyDialog() {
60
void KrKeyDialog::slotImportShortcuts() {
61
// find $KDEDIR/share/apps/krusader
62
QString basedir = KGlobal::dirs()->findResourceDir("appdata", "total_commander.keymap");
63
// let the user select a file to load
64
QString filename = KFileDialog::getOpenFileName(basedir, i18n(FILE_FILTER), 0, i18n("Select a keymap file"));
65
if ( filename.isEmpty() )
68
KConfig conf( filename, KConfig::NoGlobals /*no KDEGlobal*/ );
69
if ( ! conf.hasGroup("Shortcuts") ) {
70
int answer = KMessageBox::warningContinueCancel( this, //parent
71
i18n("This file does not seem to be a valid keymap.\n"
72
"It may be a keymap using a legacy format. The import can't be undone!"), //text
73
i18n("Try to import legacy format?"), //caption
74
KGuiItem( i18n("Import anyway") ), //Label for the continue-button
75
KStandardGuiItem::cancel(),
76
"Confirm Import Legacy Shortcuts" //dontAskAgainName (for the config-file)
78
if ( answer == KMessageBox::Continue )
79
importLegacyShortcuts( filename );
87
void KrKeyDialog::importLegacyShortcuts( const QString& file ) {
89
* This is basicaly Shie's code. It's copied from Kronfigurator's loog&feel page and adapted to the dialog
91
// check if there's an info file with the keymap
92
QFile info(file+".info");
93
if (info.open(QIODevice::ReadOnly)) {
94
QTextStream stream(&info);
95
QStringList infoText = stream.readAll().split("\n");
96
if (KMessageBox::questionYesNoList(krApp, i18n("The following information was attached to the keymap. Do you really want to import this keymap?"), infoText)!=KMessageBox::Yes)
102
if (!f.open(QIODevice::ReadOnly)) {
103
krOut << "Error opening " << file << endl;
107
QDataStream stream(&f);
110
while (!stream.atEnd()) {
111
stream >> actionName >> key;
112
action = krApp->actionCollection()->action(actionName);
114
action->setShortcut(key);
115
// krOut << "set shortcut for " << actionName <<endl;
117
krOut << "unknown action " << actionName << endl;
122
KMessageBox::information( this, // parent
123
i18n("Please restart this dialog in order to see the changes"), // text
124
i18n("Legacy import completed") // caption
128
void KrKeyDialog::slotExportShortcuts() {
129
QString filename = KFileDialog::getSaveFileName( QString(), i18n(FILE_FILTER), 0, i18n("Select a keymap file") );
130
if ( filename.isEmpty() )
134
KMessageBox::warningContinueCancel( this,
135
i18n("<qt>File <b>%1</b> already exists. Do you really want to overwrite it?</qt>", filename),
136
i18n("Warning"), KGuiItem( i18n("Overwrite") ) )
137
!= KMessageBox::Continue)
139
if ( f.open( QIODevice::WriteOnly ) )
140
// This is the only way to detect if the file is writable since we don't get feetback from KConfig's sync
141
// Additionaly this prevents merging if the file already contains some shortcuts
144
KMessageBox::error( this, i18n("<qt>Can't open <b>%1</b> for writing!</qt>", filename) );
148
KConfig conf( filename, KConfig::NoGlobals );
149
KConfigGroup cg = conf.group( "Shortcuts" );
151
// unfortunately we can't use this function since it only writes the actions which are different from default.
152
//krApp->actionCollection()->writeShortcutSettings( "Shortcuts", &conf );
153
krApp->actionCollection()->writeSettings( &cg, true /* write all actions */ );
154
// That does KActionShortcutList::writeSettings for us
155
//conf.sync(); // write back all changes
39
KrKeyDialog::KrKeyDialog(QWidget * parent) : KShortcutsDialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed /* allow letter shortcuts */, parent)
41
addCollection(krApp->actionCollection());
43
// HACK This fetches the layout of the buttonbox from KDialog, although it is not accessable with KDialog's API
44
// None the less it's quite save to use since this implementation hasn't changed since KDE-3.3 (I haven't looked at earlier
45
// versions since we don't support them) and now all work is done in KDE-4.
46
QWidget* buttonBox = static_cast<QWidget*>(button(KDialog::Ok)->parent());
47
QBoxLayout* buttonBoxLayout = static_cast<QBoxLayout*>(buttonBox->layout());
49
KPushButton* importButton = new KPushButton(i18n("Import shortcuts"), buttonBox);
50
importButton->setWhatsThis(i18n("Load a keybinding profile, e.g., total_commander.keymap"));
51
buttonBoxLayout->insertWidget(1, importButton); // the defaults-button should stay on position 0
52
connect(importButton, SIGNAL(clicked()), SLOT(slotImportShortcuts()));
54
KPushButton* exportButton = new KPushButton(i18n("Export shortcuts"), buttonBox);
55
exportButton->setWhatsThis(i18n("Save current keybindings in a keymap file."));
56
buttonBoxLayout->insertWidget(2, exportButton);
57
connect(exportButton, SIGNAL(clicked()), SLOT(slotExportShortcuts()));
59
// Also quite HACK 'isch but unfortunately KKeyDialog don't giveus access to this widget
60
_chooser = static_cast<KShortcutsEditor*>(mainWidget());
62
configure(true /* SaveSettings */); // this runs the dialog
65
KrKeyDialog::~KrKeyDialog()
69
void KrKeyDialog::slotImportShortcuts()
71
// find $KDEDIR/share/apps/krusader
72
QString basedir = KGlobal::dirs()->findResourceDir("appdata", "total_commander.keymap");
73
// let the user select a file to load
74
QString filename = KFileDialog::getOpenFileName(basedir, i18n(FILE_FILTER), 0, i18n("Select a keymap file"));
75
if (filename.isEmpty())
78
KConfig conf(filename, KConfig::NoGlobals /*no KDEGlobal*/);
79
if (! conf.hasGroup("Shortcuts")) {
80
int answer = KMessageBox::warningContinueCancel(this, //parent
81
i18n("This file does not seem to be a valid keymap.\n"
82
"It may be a keymap using a legacy format. The import can't be undone!"), //text
83
i18n("Try to import legacy format?"), //caption
84
KGuiItem(i18n("Import anyway")), //Label for the continue-button
85
KStandardGuiItem::cancel(),
86
"Confirm Import Legacy Shortcuts" //dontAskAgainName (for the config-file)
88
if (answer == KMessageBox::Continue)
89
importLegacyShortcuts(filename);
96
void KrKeyDialog::importLegacyShortcuts(const QString& file)
99
* This is basicaly Shie's code. It's copied from Kronfigurator's loog&feel page and adapted to the dialog
101
// check if there's an info file with the keymap
102
QFile info(file + ".info");
103
if (info.open(QIODevice::ReadOnly)) {
104
QTextStream stream(&info);
105
QStringList infoText = stream.readAll().split('\n');
106
if (KMessageBox::questionYesNoList(krApp, i18n("The following information was attached to the keymap. Do you really want to import this keymap?"), infoText) != KMessageBox::Yes)
112
if (!f.open(QIODevice::ReadOnly)) {
113
krOut << "Error opening " << file << endl;
117
QDataStream stream(&f);
120
while (!stream.atEnd()) {
121
stream >> actionName >> key;
122
action = krApp->actionCollection()->action(actionName);
124
action->setShortcut(key);
125
// krOut << "set shortcut for " << actionName <<endl;
127
krOut << "unknown action " << actionName << endl;
132
KMessageBox::information(this, // parent
133
i18n("Please restart this dialog in order to see the changes"), // text
134
i18n("Legacy import completed") // caption
138
void KrKeyDialog::slotExportShortcuts()
140
QString filename = KFileDialog::getSaveFileName(QString(), i18n(FILE_FILTER), 0, i18n("Select a keymap file"));
141
if (filename.isEmpty())
145
KMessageBox::warningContinueCancel(this,
146
i18n("<qt>File <b>%1</b> already exists. Do you really want to overwrite it?</qt>", filename),
147
i18n("Warning"), KGuiItem(i18n("Overwrite")))
148
!= KMessageBox::Continue)
150
if (f.open(QIODevice::WriteOnly))
151
// This is the only way to detect if the file is writable since
152
// we don't get feetback from KConfig's sync
153
// additionally this prevents merging if the file already contains some
157
KMessageBox::error(this, i18n("<qt>Can't open <b>%1</b> for writing!</qt>", filename));
161
KConfig conf(filename, KConfig::NoGlobals);
162
KConfigGroup cg = conf.group("Shortcuts");
164
// unfortunately we can't use this function since it only writes the actions which are different from default.
165
//krApp->actionCollection()->writeShortcutSettings( "Shortcuts", &conf );
166
krApp->actionCollection()->writeSettings(&cg, true /* write all actions */);
167
// That does KActionShortcutList::writeSettings for us
168
//conf.sync(); // write back all changes
158
171
#include "krkeydialog.moc"