1/***************************************************************************
2 kfilereplace.cpp - KFileReplace shell implementation
3 -------------------
4 begin : Thu Sep 16 14:14:09 2004
5 copyright : (C) 2004 by Andras Mantia <amantia@kde.org>
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17//kde includes
18#include <kedittoolbar.h>
19#include <klibloader.h>
20#include <klocale.h>
21#include <kshortcutsdialog.h>
22#include <kmessagebox.h>
23#include <kxmlguifactory.h>
24//app includes
25#include "kfilereplace.h"
26//Added by qt3to4:
27#include <kactioncollection.h>
28#include <kstandardaction.h>
29
30KFileReplace::KFileReplace()
31 : KParts::MainWindow()
32{
33 setObjectName("KFileReplace");
34 KLibFactory *factory = KLibLoader::self()->factory("libkfilereplacepart");
35 if (factory)
36 {
37 m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(this, "KParts::ReadOnlyPart"));
38
39 if (m_part)
40 {
41 m_part->setObjectName("kfilereplace_part");
42 setCentralWidget(m_part->widget());
43 KStandardAction::quit(this, SLOT(close()), actionCollection());
44 KStandardAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
45 KStandardAction::configureToolbars(this, SLOT(slotConfigureToolbars()), actionCollection());
46 setStandardToolBarMenuEnabled(true);
47 createGUI(m_part);
48 removeDuplicatedActions();
49 } else
50 {
51 KMessageBox::error(this, i18n("Could not load the KFileReplace part."));
52 close();
53 return;
54 }
55 }
56 else
57 {
58 KMessageBox::error(this, i18n("Could not find the KFileReplace part."));
59 close();
60 return;
61 }
62}
63
64
65KFileReplace::~KFileReplace()
66{
67}
68
69void KFileReplace::openURL(const KUrl &url)
70{
71 m_part->openUrl(url);
72}
73
74void KFileReplace::slotConfigureKeys()
75{
76 KShortcutsDialog dlg( KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this );
77 QList<KXMLGUIClient*> clients = guiFactory()->clients();
78 foreach(KXMLGUIClient *client, clients)
79 dlg.addCollection(client->actionCollection());
80 dlg.configure();
81}
82
83void KFileReplace::slotConfigureToolbars()
84{
85 saveMainWindowSettings(KGlobal::config()->group( autoSaveGroup()) );
86 KEditToolBar dlg(factory());
87 connect(&dlg, SIGNAL(newToolbarConfig()),
88 this, SLOT(applyNewToolbarConfig()));
89 dlg.exec();
90}
91
92void KFileReplace::applyNewToolbarConfig()
93{
94 applyMainWindowSettings(KGlobal::config()->group( autoSaveGroup()) );
95}
96
97
98void KFileReplace::removeDuplicatedActions()
99{
100 KActionCollection* part_action_collection = m_part->actionCollection();
101 QAction* part_about_action = part_action_collection->action("help_about_kfilereplace");
102 QAction* part_report_action = part_action_collection->action("report_bug");
103 QAction* part_help_action= part_action_collection->action("help_kfilereplace");
104
105 if (!part_about_action || !part_report_action || !part_help_action || !part_action_collection)
106 return;
107
108 QWidget* container = part_about_action->associatedWidgets().value(0);
109 container->removeAction(part_about_action);
110 container->removeAction(part_report_action);
111 container->removeAction(part_help_action);
112 part_action_collection->removeAction(part_about_action);
113 part_action_collection->removeAction(part_report_action);
114 part_action_collection->removeAction(part_help_action);
115}
116
117#include "kfilereplace.moc"
118