27 #include <KApplication>
29 #include <KHistoryComboBox>
30 #include <KRecentFilesAction>
32 #include <KDirSelectDialog>
33 #include <KEditToolBar>
35 #include <KStandardShortcut>
36 #include <KFileDialog>
39 #include <KMessageBox>
44 #include <KUrlCompletion>
48 #include <KConfigGroup>
49 #include <KShortcutsDialog>
50 #include <KSharedConfig>
51 #include <KStandardAction>
52 #include <KActionCollection>
59 KPluginFactory *factory = KPluginLoader(
QLatin1String(
"filelightpart" )).factory();
62 KMessageBox::error(
this, i18n(
"Unable to load the Filelight Part.\nPlease make sure Filelight was correctly installed."));
67 m_part =
static_cast<Part *
>(factory->create<KParts::ReadOnlyPart>(
this));
70 setStandardToolBarMenuEnabled(
true);
73 setCentralWidget(m_part->widget());
77 connect(m_part, SIGNAL(started(KIO::Job*)), SLOT(scanStarted()));
78 connect(m_part, SIGNAL(completed()), SLOT(scanCompleted()));
79 connect(m_part, SIGNAL(canceled(
QString)), SLOT(scanFailed()));
81 connect(m_part, SIGNAL(canceled(
QString)), m_histories, SLOT(stop()));
82 connect(BrowserExtension::childObject(m_part), SIGNAL(openUrlNotify()), SLOT(urlAboutToChange()));
84 const KConfigGroup config = KGlobal::config()->group(
"general");
85 m_combo->setHistoryItems(config.readPathEntry(
"comboHistory",
QStringList()));
87 KMessageBox::error(
this, i18n(
"Unable to create part widget."));
94 inline void MainWindow::setupActions()
96 KActionCollection *
const ac = actionCollection();
98 m_combo =
new KHistoryComboBox(
this);
99 m_combo->setCompletionObject(
new KUrlCompletion(KUrlCompletion::DirCompletion));
100 m_combo->setAutoDeleteCompletionObject(
true);
101 m_combo->setSizePolicy(
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
102 m_combo->setDuplicatesEnabled(
false);
104 KStandardAction::open(
this, SLOT(slotScanFolder()), ac);
105 KStandardAction::quit(
this, SLOT(close()), ac);
106 KStandardAction::up(
this, SLOT(slotUp()), ac);
107 KStandardAction::configureToolbars(
this, SLOT(configToolbars()), ac);
108 KStandardAction::keyBindings(
this, SLOT(configKeys()), ac);
112 action = ac->addAction(
QLatin1String(
"scan_home" ),
this, SLOT(slotScanHomeFolder()));
113 action->setText(i18n(
"Scan &Home Folder"));
115 action->setShortcut(
QKeySequence(Qt::CTRL + Qt::Key_Home));
117 action = ac->addAction(
QLatin1String(
"scan_root" ),
this, SLOT(slotScanRootFolder()));
118 action->setText(i18n(
"Scan &Root Folder"));
121 action = ac->addAction(
QLatin1String(
"scan_rescan" ), m_part, SLOT(rescan()));
122 action->setText(i18n(
"Rescan"));
124 action->setShortcut(KStandardShortcut::reload());
127 action = ac->addAction(
QLatin1String(
"scan_stop" ),
this, SLOT(slotAbortScan()));
128 action->setText(i18n(
"Stop"));
130 action->setShortcut(Qt::Key_Escape);
132 action = ac->addAction(
QLatin1String(
"go" ), m_combo, SIGNAL(returnPressed()));
133 action->setText(i18n(
"Go"));
134 action->setIcon(KIcon(
QLatin1String(
"go-jump-locationbar" )));
136 action = ac->addAction(
QLatin1String(
"location_bar" ), 0, 0);
137 action->setText(i18n(
"Location Bar"));
138 action->setDefaultWidget(m_combo);
140 action = ac->addAction(
QLatin1String(
"scan_folder" ),
this, SLOT(slotScanFolder()));
141 action->setText(i18n(
"Scan Folder"));
144 m_recentScans =
new KRecentFilesAction(i18n(
"&Recent Scans"), ac);
145 m_recentScans->setMaxItems(8);
149 m_recentScans->loadEntries(KGlobal::config()->group(
"general"));
151 connect(m_recentScans, SIGNAL(urlSelected(KUrl)), SLOT(slotScanUrl(KUrl)));
152 connect(m_combo, SIGNAL(returnPressed()), SLOT(slotComboScan()));
153 connect(m_histories, SIGNAL(activated(KUrl)), SLOT(slotScanUrl(KUrl)));
158 KConfigGroup config = KGlobal::config()->group(
"general");
160 m_recentScans->saveEntries(config);
161 config.writePathEntry(
"comboHistory", m_combo->historyItems());
164 KParts::MainWindow::closeEvent(event);
167 inline void MainWindow::configToolbars()
169 KEditToolBar dialog(factory(),
this);
174 applyMainWindowSettings(KGlobal::config()->group(
"window"));
178 inline void MainWindow::configKeys()
180 KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed,
this,
true);
183 inline void MainWindow::slotScanFolder()
185 slotScanUrl(KFileDialog::getExistingDirectoryUrl(m_part->url(),
this, i18n(
"Select Folder to Scan")));
188 inline void MainWindow::slotScanHomeFolder() {
191 inline void MainWindow::slotScanRootFolder() {
194 inline void MainWindow::slotUp() {
195 slotScanUrl(m_part->url().upUrl());
198 inline void MainWindow::slotComboScan()
200 QString path = m_combo->lineEdit()->text();
202 KUrl url = KUrl(path);
204 if (url.isRelative())
207 path = KShell::tildeExpand(path);
209 if (slotScanPath(path))
210 m_combo->addToHistory(path);
213 inline bool MainWindow::slotScanPath(
const QString &path)
215 return slotScanUrl(KUrl(path));
218 bool MainWindow::slotScanUrl(
const KUrl &url)
220 const KUrl oldUrl = m_part->url();
224 m_histories->
push(oldUrl);
231 inline void MainWindow::slotAbortScan()
233 if (m_part->
closeUrl()) action(
"scan_stop")->setEnabled(
false);
236 inline void MainWindow::scanStarted()
239 m_combo->clearFocus();
242 inline void MainWindow::scanFailed()
246 m_combo->lineEdit()->clear();
249 void MainWindow::scanCompleted()
252 const KUrl url = m_part->url();
256 m_combo->lineEdit()->setText(m_part->
prettyUrl());
258 if (url.path(KUrl::LeaveTrailingSlash) ==
QLatin1String(
"/" )) {
259 goUp->setEnabled(
false);
263 goUp->setHelpText(url.upUrl().path(KUrl::LeaveTrailingSlash));
265 m_recentScans->addUrl(url);
268 inline void MainWindow::urlAboutToChange()
273 m_histories->
push(m_part->url());
283 m_histories->
save(configgroup);
284 configgroup.writeEntry(
"currentMap", m_part->url().path());
289 m_histories->
restore(configgroup);
290 slotScanPath(configgroup.group(
"General").readEntry(
"currentMap",
QString()));
295 #include "mainWindow.moc"
virtual void closeEvent(QCloseEvent *event)
void save(KConfigGroup &configgroup)
QString prettyUrl() const
virtual bool openUrl(const KUrl &)
virtual void readProperties(const KConfigGroup &)
virtual void saveProperties(KConfigGroup &)
void restore(const KConfigGroup &configgroup)