Repository navigation
Expand file tree
/
Copy pathdesktopmainwindow.cpp
More file actions
344 lines (279 loc) · 7.83 KB
/
Copy pathdesktopmainwindow.cpp
File metadata and controls
344 lines (279 loc) · 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
Copyright (C) 2021 Chris Moore <chris@mooreonline.org>
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <QDebug>
#include <QProcess>
#include <QStandardPaths>
#include "desktopmainwindow.h"
#include "bookmarkaction.h"
#include "application.h"
#include "gotofolderwindow.h"
using namespace Filer;
DesktopMainWindow::DesktopMainWindow(QWidget *parent) : QMainWindow(parent)
{
ui.setupUi(this);
// Delete the actions that are not applicable to the desktop - they will
// be removed from the menubar
delete ui.actionNewWin;
delete ui.actionCloseTab;
delete ui.actionCloseWindow;
delete ui.actionIconView;
delete ui.actionCompactView;
delete ui.actionDetailedList;
delete ui.actionThumbnailView;
delete ui.actionFilter;
delete ui.actionGoBack;
delete ui.actionGoForward;
delete ui.actionGo;
delete ui.actionOpenAsRoot;
// load bookmark menu
bookmarks = fm_bookmarks_dup();
g_signal_connect(bookmarks, "changed", G_CALLBACK(onBookmarksChanged), this);
loadBookmarksMenu();
}
QMenuBar *DesktopMainWindow::getMenuBar() const
{
return ui.menubar;
}
void DesktopMainWindow::setShowHidden(bool hidden)
{
ui.actionShowHidden->setChecked(hidden);
}
void DesktopMainWindow::setSortColumn(int column)
{
ui.actionByFileName->setChecked(column == 0);
ui.actionByFileType->setChecked(column == 1);
ui.actionByFileSize->setChecked(column == 2);
ui.actionByMTime->setChecked(column == 3);
ui.actionByOwner->setChecked(column == 4);
}
void DesktopMainWindow::setSortOrder(Qt::SortOrder order)
{
ui.actionAscending->setChecked(order == Qt::AscendingOrder);
ui.actionDescending->setChecked(order == Qt::DescendingOrder);
}
void DesktopMainWindow::setFolderFirst(bool first)
{
ui.actionFolderFirst->setChecked(first);
}
void DesktopMainWindow::setCaseSensitive(Qt::CaseSensitivity sensitivity)
{
ui.actionCaseSensitive->setChecked(sensitivity == Qt::CaseSensitive);
}
void Filer::DesktopMainWindow::on_actionOpen_triggered()
{
Q_EMIT open();
}
void Filer::DesktopMainWindow::on_actionOpenWith_triggered()
{
Q_EMIT openWith();
}
void Filer::DesktopMainWindow::on_actionShowContents_triggered()
{
Q_EMIT showContents();
}
void DesktopMainWindow::on_actionNewFolder_triggered()
{
Q_EMIT newFolder();
}
void DesktopMainWindow::on_actionNewBlankFile_triggered()
{
Q_EMIT newBlankFile();
}
void DesktopMainWindow::on_actionFileProperties_triggered()
{
Q_EMIT fileProperties();
}
void DesktopMainWindow::on_actionCut_triggered()
{
Q_EMIT cut();
}
void DesktopMainWindow::on_actionCopy_triggered()
{
Q_EMIT copy();
}
void DesktopMainWindow::on_actionPaste_triggered()
{
Q_EMIT paste();
}
void DesktopMainWindow::on_actionDuplicate_triggered()
{
Q_EMIT duplicate();
}
void DesktopMainWindow::on_actionEmptyTrash_triggered()
{
Q_EMIT emptyTrash();
}
void DesktopMainWindow::on_actionDelete_triggered()
{
Q_EMIT del();
}
void DesktopMainWindow::on_actionRename_triggered()
{
Q_EMIT rename();
}
void DesktopMainWindow::on_actionSelectAll_triggered()
{
Q_EMIT selectAll();
}
void DesktopMainWindow::on_actionInvertSelection_triggered()
{
Q_EMIT invert();
}
void DesktopMainWindow::on_actionPreferences_triggered()
{
Q_EMIT preferences();
}
void DesktopMainWindow::on_actionGoUp_triggered()
{
Q_EMIT goUp();
}
void DesktopMainWindow::on_actionHome_triggered()
{
Q_EMIT openHome();
}
void DesktopMainWindow::on_actionReload_triggered()
{
Q_EMIT reload();
}
void DesktopMainWindow::on_actionGoToFolder_triggered()
{
GotoFolderDialog* gotoFolderDialog = new GotoFolderDialog(this);
int code = gotoFolderDialog->exec();
if (code == QDialog::Accepted) {
Q_EMIT openFolder(gotoFolderDialog->getPath());
}
}
void DesktopMainWindow::on_actionShowHidden_triggered(bool check)
{
Q_EMIT showHidden(check);
}
void DesktopMainWindow::on_actionByFileName_triggered(bool checked)
{
Q_EMIT sortColumn(0);
}
void DesktopMainWindow::on_actionByMTime_triggered(bool checked)
{
Q_EMIT sortColumn(3);
}
void DesktopMainWindow::on_actionByOwner_triggered(bool checked)
{
Q_EMIT sortColumn(4);
}
void DesktopMainWindow::on_actionByFileType_triggered(bool checked)
{
Q_EMIT sortColumn(1);
}
void DesktopMainWindow::on_actionByFileSize_triggered(bool checked)
{
Q_EMIT sortColumn(2);
}
void DesktopMainWindow::on_actionAscending_triggered(bool checked)
{
Q_EMIT sortOrder(Qt::AscendingOrder);
}
void DesktopMainWindow::on_actionDescending_triggered(bool checked)
{
Q_EMIT sortOrder(Qt::DescendingOrder);
}
void DesktopMainWindow::on_actionFolderFirst_triggered(bool checked)
{
Q_EMIT folderFirst(checked);
}
void DesktopMainWindow::on_actionCaseSensitive_triggered(bool checked)
{
Q_EMIT caseSensitive(checked ? Qt::CaseSensitive : Qt::CaseInsensitive);
}
void DesktopMainWindow::on_actionApplications_triggered()
{
Q_EMIT openFolder(QString("file:///Applications"));
}
void DesktopMainWindow::on_actionUtilities_triggered()
{
Q_EMIT openFolder(QString("file:///Applications/Utilities"));
}
void DesktopMainWindow::on_actionDocuments_triggered()
{
Q_EMIT openDocuments();
}
void DesktopMainWindow::on_actionDownloads_triggered()
{
Q_EMIT openDownloads();
}
void DesktopMainWindow::on_actionComputer_triggered()
{
Q_EMIT openFolder(QString("/media"));
}
void DesktopMainWindow::on_actionTrash_triggered()
{
Q_EMIT openTrash();
}
void DesktopMainWindow::on_actionNetwork_triggered()
{
qDebug() << "Launching Zeroconf.app using the 'launch' command";
QProcess::startDetached("launch", {"Zeroconf"});
}
void DesktopMainWindow::on_actionDesktop_triggered()
{
Q_EMIT openDesktop();
}
void DesktopMainWindow::on_actionEditBookmarks_triggered()
{
Q_EMIT editBookmarks();
}
void DesktopMainWindow::on_actionOpenTerminal_triggered()
{
Q_EMIT openTerminal();
}
void DesktopMainWindow::on_actionFindFiles_triggered()
{
Q_EMIT search();
}
void DesktopMainWindow::on_actionAbout_triggered()
{
Q_EMIT about();
}
void DesktopMainWindow::onBookmarkActionTriggered()
{
Fm::BookmarkAction* action = static_cast<Fm::BookmarkAction*>(sender());
FmPath* path = action->path();
if(path) {
qDebug() << "bookmark path: " << fm_path_to_str(path);
Q_EMIT openFolder(fm_path_to_str(path));
}
}
void DesktopMainWindow::onBookmarksChanged(FmBookmarks* bookmarks, DesktopMainWindow* pThis) {
// delete existing items
QList<QAction*> actions = pThis->ui.menu_Bookmarks->actions();
QList<QAction*>::const_iterator it = actions.begin();
QList<QAction*>::const_iterator last_it = actions.end() - 2;
while(it != last_it) {
QAction* action = *it;
++it;
pThis->ui.menu_Bookmarks->removeAction(action);
}
pThis->loadBookmarksMenu();
}
void DesktopMainWindow::loadBookmarksMenu() {
GList* allBookmarks = fm_bookmarks_get_all(bookmarks);
QAction* before = ui.actionAddToBookmarks;
for(GList* l = allBookmarks; l; l = l->next) {
FmBookmarkItem* item = reinterpret_cast<FmBookmarkItem*>(l->data);
Fm::BookmarkAction* action = new Fm::BookmarkAction(item, ui.menu_Bookmarks);
connect(action, &QAction::triggered, this, &DesktopMainWindow::onBookmarkActionTriggered);
ui.menu_Bookmarks->insertAction(before, action);
}
ui.menu_Bookmarks->insertSeparator(before);
g_list_free_full(allBookmarks, (GDestroyNotify)fm_bookmark_item_unref);
}