Merge lp:~carlos-mazieri/ubuntu-filemanager-app/app-simple-test-ui into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Carlos Jose Mazieri
Approved revision: 252
Merged at revision: 259
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/app-simple-test-ui
Merge into: lp:ubuntu-filemanager-app
Diff against target: 2026 lines (+1382/-465)
11 files modified
src/plugin/test_folderlistmodel/simpleUI/placesmodel.cpp (+94/-0)
src/plugin/test_folderlistmodel/simpleUI/placesmodel.h (+63/-0)
src/plugin/test_folderlistmodel/simpleUI/res.qrc (+23/-0)
src/plugin/test_folderlistmodel/simpleUI/resources/xterm_48x48.xpm (+53/-0)
src/plugin/test_folderlistmodel/simpleUI/simplelist.cpp (+156/-232)
src/plugin/test_folderlistmodel/simpleUI/simplelist.h (+31/-25)
src/plugin/test_folderlistmodel/simpleUI/simplelist.ui (+354/-205)
src/plugin/test_folderlistmodel/simpleUI/simpleslots.cpp (+178/-0)
src/plugin/test_folderlistmodel/simpleUI/simpleui.pro (+4/-3)
src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.cpp (+326/-0)
src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.h (+100/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/app-simple-test-ui
Reviewer Review Type Date Requested Status
Carlos Jose Mazieri Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+230667@code.launchpad.net

Commit message

New C++ UI with Trash and Places Model

Description of the change

C++ Test UI refactored

New C++ UI with Trash and Places Model, it is used for testing the model.

This change does not affect production filemanager.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Jenkins compiles it, so I'm okay with it.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

I am going to top approve it myself as it is important do have another view to test the model.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/plugin/test_folderlistmodel/simpleUI/placesmodel.cpp'
2--- src/plugin/test_folderlistmodel/simpleUI/placesmodel.cpp 1970-01-01 00:00:00 +0000
3+++ src/plugin/test_folderlistmodel/simpleUI/placesmodel.cpp 2014-08-13 15:58:44 +0000
4@@ -0,0 +1,94 @@
5+/**************************************************************************
6+ *
7+ * Copyright 2014 Canonical Ltd.
8+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
9+ *
10+ * This program is free software; you can redistribute it and/or modify
11+ * it under the terms of the GNU Lesser General Public License as published by
12+ * the Free Software Foundation; version 3.
13+ *
14+ * This program is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU Lesser General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU Lesser General Public License
20+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21+ *
22+ * File: placesmodel.cpp
23+ * Date: 21/04/2014
24+ */
25+
26+#include "placesmodel.h"
27+#include "locationurl.h"
28+#include <QDir>
29+#include <QIcon>
30+#include <QStandardPaths>
31+
32+
33+PlacesModel::PlacesModel(QObject *parent) :
34+ QAbstractListModel(parent)
35+{
36+ QLatin1String doc("Documents");
37+ QLatin1String dow("Downloads");
38+
39+ addPlace("Home", ":/resources/resources/home-page.png", QStringList(QDir::homePath()));
40+
41+ addPlace(doc, ":/resources/resources/document_folder.png",
42+ QStringList() << QStandardPaths::displayName(QStandardPaths::DocumentsLocation)
43+ << QDir::homePath() + QDir::separator() + doc
44+ );
45+
46+ addPlace(dow, ":/resources/resources/downloads_folder.png",
47+ QStringList() << QStandardPaths::displayName(QStandardPaths::DownloadLocation)
48+ << QDir::homePath() + QDir::separator() + dow
49+ );
50+
51+ addPlace("Temp", ":/resources/resources/temp_folder.png", QStringList(QDir::tempPath()));
52+
53+ addPlace("Root", ":/resources/resources/red_folder.png", QStringList(QDir::rootPath()));
54+
55+ addPlace("Trash", ":/resources/resources/recyclebin_full.png", QStringList(LocationUrl::TrashRootURL));
56+}
57+
58+
59+QVariant PlacesModel::data(const QModelIndex &index, int role) const
60+{
61+ if ( role == Qt::DisplayRole)
62+ {
63+ return m_places.at(index.row()).name;
64+ }
65+ if (role == Qt::DecorationRole)
66+ {
67+ return m_places.at(index.row()).icon;
68+ }
69+ return QVariant();
70+}
71+
72+
73+QString PlacesModel::pathFrom(int row) const
74+{
75+ return m_places.at(row).urlPath;
76+}
77+
78+
79+void PlacesModel::addPlace(const QString &n, const QString &i, const QStringList &u)
80+{
81+ Place place(n,i);
82+ if (u.count() == 1)
83+ {
84+ place.urlPath = u.at(0);
85+ m_places.append(place);
86+ return;
87+ }
88+
89+ for (int counter = 0 ; counter < u.count(); ++counter)
90+ {
91+ if (QFileInfo(u.at(counter)).exists())
92+ {
93+ place.urlPath = u.at(counter);
94+ m_places.append(place);
95+ return;
96+ }
97+ }
98+}
99
100=== added file 'src/plugin/test_folderlistmodel/simpleUI/placesmodel.h'
101--- src/plugin/test_folderlistmodel/simpleUI/placesmodel.h 1970-01-01 00:00:00 +0000
102+++ src/plugin/test_folderlistmodel/simpleUI/placesmodel.h 2014-08-13 15:58:44 +0000
103@@ -0,0 +1,63 @@
104+/**************************************************************************
105+ *
106+ * Copyright 2014 Canonical Ltd.
107+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
108+ *
109+ * This program is free software; you can redistribute it and/or modify
110+ * it under the terms of the GNU Lesser General Public License as published by
111+ * the Free Software Foundation; version 3.
112+ *
113+ * This program is distributed in the hope that it will be useful,
114+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
115+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
116+ * GNU Lesser General Public License for more details.
117+ *
118+ * You should have received a copy of the GNU Lesser General Public License
119+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
120+ *
121+ * File: placesmodel.h
122+ * Date: 21/04/2014
123+ */
124+
125+#ifndef PLACESMODEL_H
126+#define PLACESMODEL_H
127+
128+#include <QAbstractListModel>
129+#include <QIcon>
130+
131+class PlacesModel : public QAbstractListModel
132+{
133+ Q_OBJECT
134+public:
135+ explicit PlacesModel(QObject *parent = 0);
136+
137+ virtual QVariant data(const QModelIndex &index, int role) const;
138+ virtual int rowCount(const QModelIndex &) const
139+ { return m_places.count(); }
140+
141+ QString pathFrom(int row) const;
142+
143+private:
144+ void addPlace(const QString& n,
145+ const QString& i,
146+ const QStringList& u);
147+
148+private:
149+ struct Place
150+ {
151+ public:
152+ Place(const QString&n, const QString& i):
153+ name(n),
154+ icon(i)
155+ {
156+
157+ }
158+ QString name;
159+ QIcon icon;
160+ QString urlPath;
161+ };
162+
163+ QList<Place> m_places;
164+};
165+
166+#endif // PLACESMODEL_H
167
168=== added file 'src/plugin/test_folderlistmodel/simpleUI/res.qrc'
169--- src/plugin/test_folderlistmodel/simpleUI/res.qrc 1970-01-01 00:00:00 +0000
170+++ src/plugin/test_folderlistmodel/simpleUI/res.qrc 2014-08-13 15:58:44 +0000
171@@ -0,0 +1,23 @@
172+<RCC>
173+ <qresource prefix="/resources">
174+ <file>resources/xterm_48x48.xpm</file>
175+ <file>resources/home-page.png</file>
176+ <file>resources/recyclebin_full.png</file>
177+ <file>resources/empty_trash.png</file>
178+ <file>resources/undo.png</file>
179+ <file>resources/go-previous.png</file>
180+ <file>resources/go-up.png</file>
181+ <file>resources/edit-rename.png</file>
182+ <file>resources/folder-new.png</file>
183+ <file>resources/copy.png</file>
184+ <file>resources/cut.png</file>
185+ <file>resources/filenew.png</file>
186+ <file>resources/remove.png</file>
187+ <file>resources/trash.png</file>
188+ <file>resources/paste.png</file>
189+ <file>resources/temp_folder.png</file>
190+ <file>resources/red_folder.png</file>
191+ <file>resources/document_folder.png</file>
192+ <file>resources/downloads_folder.png</file>
193+ </qresource>
194+</RCC>
195
196=== added directory 'src/plugin/test_folderlistmodel/simpleUI/resources'
197=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/copy.png'
198Binary files src/plugin/test_folderlistmodel/simpleUI/resources/copy.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/copy.png 2014-08-13 15:58:44 +0000 differ
199=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/cut.png'
200Binary files src/plugin/test_folderlistmodel/simpleUI/resources/cut.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/cut.png 2014-08-13 15:58:44 +0000 differ
201=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/document_folder.png'
202Binary files src/plugin/test_folderlistmodel/simpleUI/resources/document_folder.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/document_folder.png 2014-08-13 15:58:44 +0000 differ
203=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/downloads_folder.png'
204Binary files src/plugin/test_folderlistmodel/simpleUI/resources/downloads_folder.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/downloads_folder.png 2014-08-13 15:58:44 +0000 differ
205=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/edit-rename.png'
206Binary files src/plugin/test_folderlistmodel/simpleUI/resources/edit-rename.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/edit-rename.png 2014-08-13 15:58:44 +0000 differ
207=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/empty_trash.png'
208Binary files src/plugin/test_folderlistmodel/simpleUI/resources/empty_trash.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/empty_trash.png 2014-08-13 15:58:44 +0000 differ
209=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/exit.png'
210Binary files src/plugin/test_folderlistmodel/simpleUI/resources/exit.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/exit.png 2014-08-13 15:58:44 +0000 differ
211=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/fileclose.png'
212Binary files src/plugin/test_folderlistmodel/simpleUI/resources/fileclose.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/fileclose.png 2014-08-13 15:58:44 +0000 differ
213=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/filenew.png'
214Binary files src/plugin/test_folderlistmodel/simpleUI/resources/filenew.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/filenew.png 2014-08-13 15:58:44 +0000 differ
215=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/fileopen.png'
216Binary files src/plugin/test_folderlistmodel/simpleUI/resources/fileopen.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/fileopen.png 2014-08-13 15:58:44 +0000 differ
217=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/folder-new.png'
218Binary files src/plugin/test_folderlistmodel/simpleUI/resources/folder-new.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/folder-new.png 2014-08-13 15:58:44 +0000 differ
219=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/go-previous.png'
220Binary files src/plugin/test_folderlistmodel/simpleUI/resources/go-previous.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/go-previous.png 2014-08-13 15:58:44 +0000 differ
221=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/go-up.png'
222Binary files src/plugin/test_folderlistmodel/simpleUI/resources/go-up.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/go-up.png 2014-08-13 15:58:44 +0000 differ
223=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/home-page.png'
224Binary files src/plugin/test_folderlistmodel/simpleUI/resources/home-page.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/home-page.png 2014-08-13 15:58:44 +0000 differ
225=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/paste.png'
226Binary files src/plugin/test_folderlistmodel/simpleUI/resources/paste.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/paste.png 2014-08-13 15:58:44 +0000 differ
227=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/recyclebin_full.png'
228Binary files src/plugin/test_folderlistmodel/simpleUI/resources/recyclebin_full.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/recyclebin_full.png 2014-08-13 15:58:44 +0000 differ
229=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/red_folder.png'
230Binary files src/plugin/test_folderlistmodel/simpleUI/resources/red_folder.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/red_folder.png 2014-08-13 15:58:44 +0000 differ
231=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/remove.png'
232Binary files src/plugin/test_folderlistmodel/simpleUI/resources/remove.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/remove.png 2014-08-13 15:58:44 +0000 differ
233=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/temp_folder.png'
234Binary files src/plugin/test_folderlistmodel/simpleUI/resources/temp_folder.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/temp_folder.png 2014-08-13 15:58:44 +0000 differ
235=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/trash.png'
236Binary files src/plugin/test_folderlistmodel/simpleUI/resources/trash.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/trash.png 2014-08-13 15:58:44 +0000 differ
237=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/undo.png'
238Binary files src/plugin/test_folderlistmodel/simpleUI/resources/undo.png 1970-01-01 00:00:00 +0000 and src/plugin/test_folderlistmodel/simpleUI/resources/undo.png 2014-08-13 15:58:44 +0000 differ
239=== added file 'src/plugin/test_folderlistmodel/simpleUI/resources/xterm_48x48.xpm'
240--- src/plugin/test_folderlistmodel/simpleUI/resources/xterm_48x48.xpm 1970-01-01 00:00:00 +0000
241+++ src/plugin/test_folderlistmodel/simpleUI/resources/xterm_48x48.xpm 2014-08-13 15:58:44 +0000
242@@ -0,0 +1,53 @@
243+/* XPM */
244+static char * xterm_48x48_xpm[] = {
245+"48 48 2 1",
246+" c #000000",
247+". c #FFFFFF",
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=== modified file 'src/plugin/test_folderlistmodel/simpleUI/simplelist.cpp'
298--- src/plugin/test_folderlistmodel/simpleUI/simplelist.cpp 2014-02-05 15:31:44 +0000
299+++ src/plugin/test_folderlistmodel/simpleUI/simplelist.cpp 2014-08-13 15:58:44 +0000
300@@ -22,6 +22,8 @@
301 #include "simplelist.h"
302 #include "ui_simplelist.h"
303 #include "dirmodel.h"
304+#include "dirselection.h"
305+#include "placesmodel.h"
306
307 #include <QDir>
308 #include <QMetaType>
309@@ -30,252 +32,174 @@
310 #include <QProgressBar>
311 #include <QMessageBox>
312 #include <QTimer>
313+#include <QLineEdit>
314+#include <QMouseEvent>
315
316 SimpleList::SimpleList(QWidget *parent) :
317- QWidget(parent),
318- ui(new Ui::SimpleList),
319- m_curRow(-1),
320- m_pbar( new QProgressBar() )
321+ QMainWindow(parent),
322+ ui(new Ui::SimpleList),
323+ m_pbar( new QProgressBar() ),
324+ m_selection(0),
325+ m_holdingCtrlKey(false),
326+ m_holdingShiftKey(false),
327+ m_button(Qt::NoButton),
328+ m_placesModel(new PlacesModel(this))
329 {
330+ //prepare UI
331 ui->setupUi(this);
332-
333+ ui->tableViewFM->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
334+ resize(1200,600);
335+ m_pbar->setMaximum(100);
336+ m_pbar->setMinimum(0);
337+
338+ ui->listViewPlaces->setModel(m_placesModel);
339+ ui->listViewPlaces->setSpacing(ui->listViewPlaces->spacing() + 7);
340+
341+ //create the model
342 m_model = new DirModel(this);
343-
344 DirModel::registerMetaTypes();
345- ui->tableView->setModel(m_model);
346-
347- connect(ui->tableView, SIGNAL(clicked(QModelIndex)),
348+ ui->tableViewFM->setModel(m_model);
349+
350+ //enable External Disk Watcher
351+ m_model->setEnabledExternalFSWatcher(true);
352+ ui->checkBoxExtFsWatcher->setChecked(true);
353+
354+ //get selection object
355+ m_selection = m_model->selectionObject();
356+
357+ //selection is handled in the model, disable it in the view
358+ ui->tableViewFM->setSelectionMode(QAbstractItemView::NoSelection);
359+ ui->tableViewFM->viewport()->installEventFilter(this);
360+
361+ //get default values from model
362+ ui->checkBoxShowDirs->setChecked(m_model->showDirectories());
363+ ui->checkBoxShowHidden->setChecked(m_model->getShowHiddenFiles());
364+ ui->checkBoxShowMediaInfo->setChecked(m_model->readsMediaMetadata());
365+ ui->checkBoxMultiSelection->setChecked(m_selection->mode() == DirSelection::Multi);
366+
367+ //start clibpboard message
368+ onClipboardChanged();
369+
370+ //start with actions disabled,
371+ //onSelectionChanged() does a basic actions allowable handling
372+ onSelectionChanged(0);
373+
374+ //connect everything
375+ do_connections();
376+
377+ //start browsing home
378+ m_model->goHome();
379+}
380+
381+
382+SimpleList::~SimpleList()
383+{
384+ delete ui;
385+}
386+
387+
388+bool SimpleList::eventFilter(QObject *obj, QEvent *event)
389+{
390+ if (obj == ui->tableViewFM->viewport() && event->type() == QEvent::MouseButtonPress)
391+ {
392+ QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
393+ m_holdingShiftKey = mouseEvent->modifiers() & Qt::ShiftModifier;;
394+ m_holdingCtrlKey = mouseEvent->modifiers() & Qt::ControlModifier;;
395+ m_button = mouseEvent->button();
396+ }
397+ return QMainWindow::eventFilter(obj, event);
398+}
399+
400+
401+void SimpleList::do_connections()
402+{
403+ connect(ui->tableViewFM, SIGNAL(clicked(QModelIndex)),
404 this, SLOT(onRowClicked(QModelIndex)));
405- connect(ui->tableView, SIGNAL(doubleClicked(QModelIndex)),
406+
407+ connect(ui->tableViewFM, SIGNAL(doubleClicked(QModelIndex)),
408 this, SLOT(onOpenItem(QModelIndex)));
409
410- connect(ui->tableView->verticalHeader(), SIGNAL(sectionClicked(int)),
411- this, SLOT(onVerticalHeaderClicked(int)));
412-
413 connect(m_model, SIGNAL(pathChanged(QString)),
414- this, SLOT(pathChanged(QString)));
415-
416- connect(ui->pushButtonCdUp, SIGNAL(clicked()), this, SLOT(onCdUP()));
417- connect(ui->pushButtonCopy, SIGNAL(clicked()), this, SLOT(onCopy()));
418- connect(ui->pushButtonCut, SIGNAL(clicked()), this, SLOT(onCut()));
419- connect(ui->pushButtonDelete, SIGNAL(clicked()), this, SLOT(onRemove()));
420- connect(ui->pushButtonGoHome, SIGNAL(clicked()), this, SLOT(onGoHome()));
421- connect(ui->pushButtonIntoDirs,SIGNAL(clicked()), this, SLOT(onCdInto()));
422- connect(ui->pushButtonNewDir, SIGNAL(clicked()), this, SLOT(onNewDir()));
423- connect(ui->pushButtonPaste, SIGNAL(clicked()), this, SLOT(onPaste()));
424- connect(ui->pushButtonRename, SIGNAL(clicked()), this, SLOT(onRename()));
425-
426- connect(ui->checkBoxShowDirs, SIGNAL(clicked(bool)), this, SLOT(onShowDirs(bool)));
427- connect(ui->checkBoxShowHidden, SIGNAL(clicked(bool)), this, SLOT(onShowHidden(bool)));
428- connect(ui->checkBoxExtFsWatcher, SIGNAL(toggled(bool)),this, SLOT(onExtFsWatcherEnabled(bool)));
429-
430- connect(ui->pushButtonOpen, SIGNAL(clicked()),
431- this, SLOT(onOpen()));
432-
433- connect(ui->lineEditOpen, SIGNAL(returnPressed()),
434- this, SLOT(onOpen()));
435-
436- ui->checkBoxShowDirs->setChecked( m_model->showDirectories() );
437-
438- resize(800,600);
439-
440- connect(m_model, SIGNAL(insertedRow(int)),
441- this, SLOT(resizeColumnForName(int)));
442-
443- connect(ui->tableView->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
444- this, SLOT(setSort(int,Qt::SortOrder)));
445+ this, SLOT(onPathChanged(QString)));
446+
447+ connect(ui->toolButtonUp, SIGNAL(clicked()), m_model, SLOT(cdUp()));
448+ connect(ui->actionCopy, SIGNAL(triggered()), m_model, SLOT(copySelection()));
449+ connect(ui->actionCut, SIGNAL(triggered()), m_model, SLOT(cutSelection()));
450+ connect(ui->actionDelete, SIGNAL(triggered()), m_model, SLOT(removeSelection()));
451+ connect(ui->actionPaste, SIGNAL(triggered()), m_model, SLOT(paste()));
452+ connect(ui->actionMoveToTrash,SIGNAL(triggered()), m_model, SLOT(moveSelectionToTrash()));
453+ connect(ui->actionTerminnal, SIGNAL(triggered()), this, SLOT(onOpenTerminal()));
454+
455+ connect(ui->actionRestoreFromTrash, SIGNAL(triggered()),
456+ m_model, SLOT(restoreSelectionFromTrash()));
457+
458+ connect(ui->checkBoxShowDirs, SIGNAL(clicked(bool)), m_model, SLOT(setShowDirectories(bool)));
459+ connect(ui->checkBoxShowHidden, SIGNAL(clicked(bool)), m_model, SLOT(setShowHiddenFiles(bool)));
460+ connect(ui->checkBoxExtFsWatcher, SIGNAL(clicked(bool)), m_model, SLOT(setEnabledExternalFSWatcher(bool)));
461+ connect(ui->checkBoxShowMediaInfo, SIGNAL(clicked(bool)),m_model, SLOT(setReadsMediaMetadata(bool)));
462+ connect(ui->checkBoxMultiSelection,SIGNAL(clicked(bool)), m_selection, SLOT(setMultiSelection(bool)));
463+
464+ connect(ui->comboBoxPath, SIGNAL(activated(int)),
465+ this, SLOT(onPathChoosedFromList(int)));
466+
467+ connect(ui->comboBoxPath->lineEdit(), SIGNAL(returnPressed()),
468+ this, SLOT(onPathComboEdited()));
469+
470+ connect(ui->tableViewFM->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
471+ this, SLOT(onSetSort(int,Qt::SortOrder)));
472
473 connect(m_model, SIGNAL(progress(int,int,int)),
474- this, SLOT(progress(int,int,int)));
475+ this, SLOT(onProgress(int,int,int)));
476
477 connect(m_model, SIGNAL(clipboardChanged()),
478- this, SLOT(clipboardChanged()));
479+ this, SLOT(onClipboardChanged()));
480
481 connect(m_model, SIGNAL(error(QString,QString)),
482- this, SLOT(error(QString,QString)));
483-
484- ui->tableView->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
485-
486- m_pbar->setMaximum(100);
487- m_pbar->setMinimum(0);
488-
489- m_model->setReadsMediaMetadata(true);
490- ui->checkBoxExtFsWatcher->click();
491- m_model->goHome();
492-
493- clipboardChanged();
494-}
495-
496-SimpleList::~SimpleList()
497-{
498- delete ui;
499-}
500-
501-void SimpleList::onRowClicked(QModelIndex index)
502-{
503- if (index.isValid())
504- {
505- m_curRow = index.row();
506- }
507- else
508- {
509- m_curRow = -1;
510- }
511-}
512-
513-
514-void SimpleList::onCdInto()
515-{
516- m_model->cdIntoIndex(m_curRow);
517-}
518-
519-void SimpleList::onGoHome()
520-{
521- m_model->goHome();
522-}
523-
524-void SimpleList::onCdUP()
525-{
526- m_model->cdUp();
527-}
528-
529-void SimpleList::onRemove()
530-{
531- m_model->removeIndex(m_curRow);
532-}
533-
534-void SimpleList::onCopy()
535-{
536- m_model->copyIndex(m_curRow);
537-}
538-
539-void SimpleList::onCut()
540-{
541- m_model->cutIndex(m_curRow);
542-}
543-
544-
545-void SimpleList::onPaste()
546-{
547- m_model->paste();
548-}
549-
550-void SimpleList::onNewDir()
551-{
552- m_model->mkdir(ui->lineEditNewDir->text());
553-}
554-
555-void SimpleList::onRename()
556-{
557- m_model->rename(m_curRow, ui->lineEditRename->text());
558-}
559-
560-void SimpleList::onShowDirs(bool show)
561-{
562- m_model->setShowDirectories(show);
563-}
564-
565-void SimpleList::onShowHidden(bool s)
566-{
567- m_model->setShowHiddenFiles(s);
568-}
569-
570-void SimpleList::onVerticalHeaderClicked(int row)
571-{
572- m_curRow = row;
573-}
574-
575-
576-void SimpleList::setSort(int col, Qt::SortOrder order)
577-{
578- if (col == 0 || col == 2)
579- {
580- if (col == 0)
581- {
582- m_model->setSortBy(DirModel::SortByName);
583- }
584- else
585- {
586- m_model->setSortBy(DirModel::SortByDate);
587- }
588- DirModel::SortOrder o = (DirModel::SortOrder)order;
589- m_model->setSortOrder(o);
590- }
591-}
592-
593-void SimpleList::clipboardChanged()
594-{
595- ui->clipboardNumber->setText( QString::number(m_model->getClipboardUrlsCounter()));
596-}
597-
598-void SimpleList::progress(int cur, int total, int percent)
599-{
600- QString p;
601- m_pbar->setValue(percent);
602- if (cur == 0 && percent == 0)
603- {
604- m_pbar->reset();
605- m_pbar->show();
606- }
607- else
608- if (percent == 100)
609- {
610- QTimer::singleShot(200, m_pbar, SLOT(hide()));
611- }
612- p.sprintf("progress(cur=%d, total=%d, percent=%d)", cur,total,percent);
613- qDebug() << p;
614-}
615-
616-
617-void SimpleList::error(QString title, QString message)
618-{
619- if (m_pbar)
620- {
621- m_pbar->hide();
622- }
623- QMessageBox::critical(this, title, message);
624-}
625-
626-void SimpleList::onOpenItem(QModelIndex index)
627-{
628- if (index.isValid())
629- {
630- m_curRow = index.row();
631- if (!m_model->openIndex(m_curRow))
632- {
633- QModelIndex idx = m_model->index(m_curRow, 0);
634- QString item = m_model->data(idx).toString();
635- error("Could not open item index", item);
636- }
637- }
638- else
639- {
640- m_curRow = -1;
641- }
642-}
643-
644-
645-void SimpleList::pathChanged(QString path)
646-{
647- this->setWindowTitle(path);
648-}
649-
650-void SimpleList::resizeColumnForName(int)
651-{
652- ui->tableView->resizeColumnToContents(0);
653-}
654-
655-
656-void SimpleList::onOpen()
657-{
658- if ( ! m_model->openPath(ui->lineEditOpen->text()) )
659- {
660- QMessageBox::critical(this, "DirModel::openIndex() failed to open" , ui->lineEditOpen->text());
661- }
662-}
663-
664-
665-void SimpleList::onExtFsWatcherEnabled(bool enable)
666-{
667- m_model->setEnabledExternalFSWatcher(enable);
668+ this, SLOT(onError(QString,QString)));
669+
670+ connect(m_selection, SIGNAL(selectionChanged(int)),
671+ this, SLOT(onSelectionChanged(int)));
672+
673+ connect(ui->listViewPlaces, SIGNAL(clicked(QModelIndex)),
674+ this, SLOT(onPlacesClicked(QModelIndex)));
675+
676+}
677+
678+//===================================================================
679+
680+/*
681+ * Simple Allowable methods, they cover not everything
682+ *
683+ * allowSelectedActions() and allowTrashActions()
684+ */
685+
686+void SimpleList::allowSelectedActions(int selectedCounter)
687+{
688+ bool enableActions = selectedCounter > 0;
689+ ui->actionRename->setEnabled(selectedCounter == 1);
690+ ui->actionDelete->setEnabled(enableActions);
691+ ui->actionCut->setEnabled(enableActions);
692+ ui->actionCopy->setEnabled(enableActions);
693+ allowTrashActions(enableActions);
694+}
695+
696+
697+void SimpleList::allowTrashActions(bool enable)
698+{
699+ if (m_model->path().startsWith("trash:/"))
700+ {
701+ ui->actionEmptyTrash->setEnabled(true);
702+ ui->actionRestoreFromTrash->setEnabled(enable);
703+ ui->actionMoveToTrash->setEnabled(false);
704+ ui->actionNewFolder->setEnabled(false);
705+ ui->actionTerminnal->setEnabled(false);
706+ }
707+ else
708+ {
709+ ui->actionEmptyTrash->setEnabled(false);
710+ ui->actionRestoreFromTrash->setEnabled(false);
711+ ui->actionMoveToTrash->setEnabled(enable);
712+ ui->actionNewFolder->setEnabled(true);
713+ ui->actionTerminnal->setEnabled(true);
714+ }
715 }
716
717=== modified file 'src/plugin/test_folderlistmodel/simpleUI/simplelist.h'
718--- src/plugin/test_folderlistmodel/simpleUI/simplelist.h 2013-07-06 14:55:25 +0000
719+++ src/plugin/test_folderlistmodel/simpleUI/simplelist.h 2014-08-13 15:58:44 +0000
720@@ -22,53 +22,59 @@
721 #ifndef SIMPLELIST_H
722 #define SIMPLELIST_H
723
724-#include <QWidget>
725+#include <QMainWindow>
726 #include <QModelIndex>
727
728 class DirModel;
729 class QProgressBar;
730+class DirSelection;
731+class PlacesModel;
732
733 namespace Ui {
734 class SimpleList;
735 }
736
737-class SimpleList : public QWidget
738+class SimpleList : public QMainWindow
739 {
740 Q_OBJECT
741
742 public:
743 explicit SimpleList(QWidget *parent = 0);
744 ~SimpleList();
745-
746+
747+protected:
748+ bool eventFilter(QObject *obj, QEvent *event);
749+
750+private:
751+ void allowSelectedActions(int selectedCounter);
752+ void allowTrashActions(bool enable);
753+ void do_connections();
754+
755 private:
756 Ui::SimpleList *ui;
757- DirModel *m_model;
758- int m_curRow;
759+ DirModel *m_model;
760 QProgressBar * m_pbar;
761+ DirSelection * m_selection;
762+ bool m_holdingCtrlKey;
763+ bool m_holdingShiftKey;
764+ Qt::MouseButton m_button;
765+ PlacesModel * m_placesModel;
766
767-private slots:
768- void onCdInto();
769- void onGoHome();
770- void onCdUP();
771- void onRemove();
772- void onCopy();
773- void onCut();
774- void onPaste();
775+private slots:
776 void onNewDir();
777- void onRename();
778- void onShowDirs(bool);
779- void onShowHidden(bool);
780+ void onRename();
781 void onRowClicked(QModelIndex);
782 void onOpenItem(QModelIndex index);
783- void onVerticalHeaderClicked(int);
784- void setSort(int col, Qt::SortOrder order);
785- void progress(int, int,int);
786- void clipboardChanged();
787- void error(QString title, QString message);
788- void pathChanged(QString path);
789- void resizeColumnForName(int);
790- void onOpen();
791- void onExtFsWatcherEnabled(bool);
792+ void onSetSort(int col, Qt::SortOrder order);
793+ void onProgress(int, int,int);
794+ void onClipboardChanged();
795+ void onError(QString title, QString message);
796+ void onPathChanged(QString path);
797+ void onPathChoosedFromList(int);
798+ void onPathComboEdited();
799+ void onSelectionChanged(int);
800+ void onPlacesClicked(QModelIndex);
801+ void onOpenTerminal();
802 };
803
804 #endif // SIMPLELIST_H
805
806=== modified file 'src/plugin/test_folderlistmodel/simpleUI/simplelist.ui'
807--- src/plugin/test_folderlistmodel/simpleUI/simplelist.ui 2013-07-06 15:13:48 +0000
808+++ src/plugin/test_folderlistmodel/simpleUI/simplelist.ui 2014-08-13 15:58:44 +0000
809@@ -1,219 +1,368 @@
810 <?xml version="1.0" encoding="UTF-8"?>
811 <ui version="4.0">
812 <class>SimpleList</class>
813- <widget class="QWidget" name="SimpleList">
814+ <widget class="QMainWindow" name="SimpleList">
815 <property name="geometry">
816 <rect>
817 <x>0</x>
818 <y>0</y>
819- <width>542</width>
820- <height>666</height>
821+ <width>1046</width>
822+ <height>608</height>
823 </rect>
824 </property>
825 <property name="windowTitle">
826- <string>SimpleList</string>
827+ <string>MainWindow</string>
828 </property>
829- <layout class="QVBoxLayout" name="verticalLayout_5">
830- <item>
831- <widget class="QSplitter" name="splitter">
832- <property name="orientation">
833- <enum>Qt::Horizontal</enum>
834- </property>
835- <widget class="QTableView" name="tableView">
836- <attribute name="horizontalHeaderShowSortIndicator" stdset="0">
837- <bool>true</bool>
838- </attribute>
839- <attribute name="verticalHeaderMinimumSectionSize">
840- <number>25</number>
841- </attribute>
842- <attribute name="verticalHeaderShowSortIndicator" stdset="0">
843- <bool>true</bool>
844- </attribute>
845- </widget>
846- <widget class="QGroupBox" name="groupBox">
847- <property name="sizePolicy">
848- <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
849- <horstretch>0</horstretch>
850- <verstretch>0</verstretch>
851- </sizepolicy>
852- </property>
853- <property name="title">
854- <string>Actions</string>
855- </property>
856- <layout class="QVBoxLayout" name="verticalLayout_4">
857- <item>
858- <widget class="QPushButton" name="pushButtonDelete">
859- <property name="text">
860- <string>delete</string>
861- </property>
862- </widget>
863- </item>
864- <item>
865- <widget class="QPushButton" name="pushButtonCopy">
866- <property name="text">
867- <string>Copy </string>
868- </property>
869- </widget>
870- </item>
871- <item>
872- <widget class="QPushButton" name="pushButtonCut">
873- <property name="text">
874- <string>Cut</string>
875- </property>
876- </widget>
877- </item>
878- <item>
879- <widget class="QPushButton" name="pushButtonPaste">
880- <property name="text">
881- <string>Paste</string>
882- </property>
883- </widget>
884- </item>
885- <item>
886- <widget class="QPushButton" name="pushButtonGoHome">
887- <property name="text">
888- <string>goHome</string>
889- </property>
890- </widget>
891- </item>
892- <item>
893- <widget class="QPushButton" name="pushButtonCdUp">
894- <property name="text">
895- <string>cdUp (back)</string>
896- </property>
897- </widget>
898- </item>
899- <item>
900- <widget class="QPushButton" name="pushButtonIntoDirs">
901- <property name="text">
902- <string>cd into (dirs)</string>
903- </property>
904- </widget>
905- </item>
906- <item>
907- <widget class="QGroupBox" name="groupBox_2">
908- <property name="title">
909- <string>Rename</string>
910- </property>
911- <layout class="QVBoxLayout" name="verticalLayout">
912- <item>
913- <widget class="QLineEdit" name="lineEditRename">
914- <property name="sizePolicy">
915- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
916- <horstretch>0</horstretch>
917- <verstretch>0</verstretch>
918- </sizepolicy>
919- </property>
920- </widget>
921- </item>
922- <item>
923- <widget class="QPushButton" name="pushButtonRename">
924- <property name="text">
925- <string>rename</string>
926- </property>
927- </widget>
928- </item>
929- </layout>
930- </widget>
931- </item>
932- <item>
933- <widget class="QGroupBox" name="groupBox_4">
934- <property name="title">
935- <string>Open Dir/Files</string>
936- </property>
937- <layout class="QVBoxLayout" name="verticalLayout_3">
938- <item>
939- <widget class="QLineEdit" name="lineEditOpen">
940- <property name="sizePolicy">
941- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
942- <horstretch>0</horstretch>
943- <verstretch>0</verstretch>
944- </sizepolicy>
945- </property>
946- </widget>
947- </item>
948- <item>
949- <widget class="QPushButton" name="pushButtonOpen">
950- <property name="text">
951- <string>Open</string>
952- </property>
953- </widget>
954- </item>
955- </layout>
956- </widget>
957- </item>
958- <item>
959- <widget class="QGroupBox" name="groupBox_3">
960- <property name="title">
961- <string>New Dir</string>
962- </property>
963- <layout class="QVBoxLayout" name="verticalLayout_2">
964- <item>
965- <widget class="QLineEdit" name="lineEditNewDir">
966- <property name="sizePolicy">
967- <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
968- <horstretch>0</horstretch>
969- <verstretch>0</verstretch>
970- </sizepolicy>
971- </property>
972- </widget>
973- </item>
974- <item>
975- <widget class="QPushButton" name="pushButtonNewDir">
976- <property name="text">
977- <string>new Dir</string>
978- </property>
979- </widget>
980- </item>
981- </layout>
982- </widget>
983- </item>
984- <item>
985- <widget class="QCheckBox" name="checkBoxShowDirs">
986- <property name="text">
987- <string>show Directories</string>
988- </property>
989- </widget>
990- </item>
991- <item>
992- <widget class="QCheckBox" name="checkBoxShowHidden">
993- <property name="text">
994- <string>show Hidden Files</string>
995- </property>
996- </widget>
997- </item>
998- <item>
999- <widget class="QCheckBox" name="checkBoxExtFsWatcher">
1000- <property name="text">
1001- <string>Ext. FS Watcher</string>
1002- </property>
1003- </widget>
1004- </item>
1005- <item>
1006- <layout class="QHBoxLayout" name="horizontalLayout">
1007- <item>
1008- <widget class="QLabel" name="label">
1009- <property name="text">
1010- <string>cliboard</string>
1011- </property>
1012- </widget>
1013- </item>
1014- <item>
1015- <widget class="QLabel" name="clipboardNumber">
1016- <property name="text">
1017- <string>0</string>
1018- </property>
1019- </widget>
1020- </item>
1021- </layout>
1022- </item>
1023- </layout>
1024- </widget>
1025- </widget>
1026- </item>
1027- </layout>
1028+ <widget class="QWidget" name="centralwidget">
1029+ <layout class="QVBoxLayout" name="verticalLayout_4">
1030+ <item>
1031+ <layout class="QHBoxLayout" name="horizontalLayout">
1032+ <item>
1033+ <widget class="QToolButton" name="toolButtonBack">
1034+ <property name="enabled">
1035+ <bool>false</bool>
1036+ </property>
1037+ <property name="text">
1038+ <string>back</string>
1039+ </property>
1040+ <property name="icon">
1041+ <iconset resource="res.qrc">
1042+ <normaloff>:/resources/resources/go-previous.png</normaloff>:/resources/resources/go-previous.png</iconset>
1043+ </property>
1044+ </widget>
1045+ </item>
1046+ <item>
1047+ <widget class="QToolButton" name="toolButtonUp">
1048+ <property name="text">
1049+ <string>Up</string>
1050+ </property>
1051+ <property name="icon">
1052+ <iconset resource="res.qrc">
1053+ <normaloff>:/resources/resources/go-up.png</normaloff>:/resources/resources/go-up.png</iconset>
1054+ </property>
1055+ </widget>
1056+ </item>
1057+ <item>
1058+ <widget class="QComboBox" name="comboBoxPath">
1059+ <property name="editable">
1060+ <bool>true</bool>
1061+ </property>
1062+ <property name="insertPolicy">
1063+ <enum>QComboBox::NoInsert</enum>
1064+ </property>
1065+ </widget>
1066+ </item>
1067+ </layout>
1068+ </item>
1069+ <item>
1070+ <layout class="QHBoxLayout" name="horizontalLayout_2">
1071+ <item>
1072+ <layout class="QVBoxLayout" name="verticalLayout_3">
1073+ <item>
1074+ <widget class="QGroupBox" name="groupBoxPlaces">
1075+ <property name="title">
1076+ <string>Places</string>
1077+ </property>
1078+ <layout class="QVBoxLayout" name="verticalLayout">
1079+ <item>
1080+ <widget class="QListView" name="listViewPlaces">
1081+ <property name="sizePolicy">
1082+ <sizepolicy hsizetype="Fixed" vsizetype="Expanding">
1083+ <horstretch>0</horstretch>
1084+ <verstretch>0</verstretch>
1085+ </sizepolicy>
1086+ </property>
1087+ </widget>
1088+ </item>
1089+ </layout>
1090+ </widget>
1091+ </item>
1092+ <item>
1093+ <widget class="QGroupBox" name="groupBoxConfig">
1094+ <property name="sizePolicy">
1095+ <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
1096+ <horstretch>0</horstretch>
1097+ <verstretch>0</verstretch>
1098+ </sizepolicy>
1099+ </property>
1100+ <property name="title">
1101+ <string>Configurations</string>
1102+ </property>
1103+ <layout class="QVBoxLayout" name="verticalLayout_2">
1104+ <property name="spacing">
1105+ <number>3</number>
1106+ </property>
1107+ <property name="leftMargin">
1108+ <number>0</number>
1109+ </property>
1110+ <property name="topMargin">
1111+ <number>5</number>
1112+ </property>
1113+ <property name="rightMargin">
1114+ <number>0</number>
1115+ </property>
1116+ <property name="bottomMargin">
1117+ <number>0</number>
1118+ </property>
1119+ <item>
1120+ <widget class="QCheckBox" name="checkBoxShowDirs">
1121+ <property name="text">
1122+ <string>show Directories</string>
1123+ </property>
1124+ </widget>
1125+ </item>
1126+ <item>
1127+ <widget class="QCheckBox" name="checkBoxShowHidden">
1128+ <property name="text">
1129+ <string>show Hidden Files</string>
1130+ </property>
1131+ </widget>
1132+ </item>
1133+ <item>
1134+ <widget class="QCheckBox" name="checkBoxShowMediaInfo">
1135+ <property name="text">
1136+ <string>show Multimedia</string>
1137+ </property>
1138+ </widget>
1139+ </item>
1140+ <item>
1141+ <widget class="QCheckBox" name="checkBoxMultiSelection">
1142+ <property name="text">
1143+ <string>activate Multiselection</string>
1144+ </property>
1145+ </widget>
1146+ </item>
1147+ <item>
1148+ <widget class="QCheckBox" name="checkBoxExtFsWatcher">
1149+ <property name="text">
1150+ <string>activate FS Watcher</string>
1151+ </property>
1152+ </widget>
1153+ </item>
1154+ </layout>
1155+ </widget>
1156+ </item>
1157+ </layout>
1158+ </item>
1159+ <item>
1160+ <widget class="QTableView" name="tableViewFM"/>
1161+ </item>
1162+ </layout>
1163+ </item>
1164+ </layout>
1165+ </widget>
1166+ <widget class="QMenuBar" name="menubar">
1167+ <property name="geometry">
1168+ <rect>
1169+ <x>0</x>
1170+ <y>0</y>
1171+ <width>1046</width>
1172+ <height>30</height>
1173+ </rect>
1174+ </property>
1175+ <property name="sizePolicy">
1176+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
1177+ <horstretch>0</horstretch>
1178+ <verstretch>0</verstretch>
1179+ </sizepolicy>
1180+ </property>
1181+ </widget>
1182+ <widget class="QStatusBar" name="statusbar"/>
1183+ <widget class="QToolBar" name="toolBar">
1184+ <property name="windowTitle">
1185+ <string>toolBar</string>
1186+ </property>
1187+ <property name="toolButtonStyle">
1188+ <enum>Qt::ToolButtonTextUnderIcon</enum>
1189+ </property>
1190+ <attribute name="toolBarArea">
1191+ <enum>TopToolBarArea</enum>
1192+ </attribute>
1193+ <attribute name="toolBarBreak">
1194+ <bool>false</bool>
1195+ </attribute>
1196+ <addaction name="actionCopy"/>
1197+ <addaction name="actionCut"/>
1198+ <addaction name="actionPaste"/>
1199+ <addaction name="separator"/>
1200+ <addaction name="actionDelete"/>
1201+ <addaction name="actionMoveToTrash"/>
1202+ <addaction name="actionRestoreFromTrash"/>
1203+ <addaction name="separator"/>
1204+ <addaction name="actionRename"/>
1205+ <addaction name="actionNewFolder"/>
1206+ <addaction name="separator"/>
1207+ <addaction name="actionUndo"/>
1208+ <addaction name="separator"/>
1209+ <addaction name="actionEmptyTrash"/>
1210+ <addaction name="separator"/>
1211+ <addaction name="actionTerminnal"/>
1212+ </widget>
1213+ <action name="actionCopy">
1214+ <property name="icon">
1215+ <iconset resource="res.qrc">
1216+ <normaloff>:/resources/resources/copy.png</normaloff>:/resources/resources/copy.png</iconset>
1217+ </property>
1218+ <property name="text">
1219+ <string>Copy</string>
1220+ </property>
1221+ <property name="toolTip">
1222+ <string>Copy Items into clipbpard</string>
1223+ </property>
1224+ <property name="shortcut">
1225+ <string>Ctrl+C</string>
1226+ </property>
1227+ </action>
1228+ <action name="actionCut">
1229+ <property name="icon">
1230+ <iconset resource="res.qrc">
1231+ <normaloff>:/resources/resources/cut.png</normaloff>:/resources/resources/cut.png</iconset>
1232+ </property>
1233+ <property name="text">
1234+ <string>Cut</string>
1235+ </property>
1236+ <property name="toolTip">
1237+ <string>Cut files into clipboard</string>
1238+ </property>
1239+ <property name="shortcut">
1240+ <string>Ctrl+X</string>
1241+ </property>
1242+ </action>
1243+ <action name="actionPaste">
1244+ <property name="icon">
1245+ <iconset resource="res.qrc">
1246+ <normaloff>:/resources/resources/paste.png</normaloff>:/resources/resources/paste.png</iconset>
1247+ </property>
1248+ <property name="text">
1249+ <string>Paste</string>
1250+ </property>
1251+ <property name="toolTip">
1252+ <string>paste clibpboard contents</string>
1253+ </property>
1254+ <property name="shortcut">
1255+ <string>Ctrl+V</string>
1256+ </property>
1257+ </action>
1258+ <action name="actionDelete">
1259+ <property name="icon">
1260+ <iconset resource="res.qrc">
1261+ <normaloff>:/resources/resources/remove.png</normaloff>:/resources/resources/remove.png</iconset>
1262+ </property>
1263+ <property name="text">
1264+ <string>Remove</string>
1265+ </property>
1266+ <property name="shortcut">
1267+ <string>Shift+Del</string>
1268+ </property>
1269+ </action>
1270+ <action name="actionMoveToTrash">
1271+ <property name="icon">
1272+ <iconset resource="res.qrc">
1273+ <normaloff>:/resources/resources/trash.png</normaloff>:/resources/resources/trash.png</iconset>
1274+ </property>
1275+ <property name="text">
1276+ <string>MoveToTrash</string>
1277+ </property>
1278+ <property name="shortcut">
1279+ <string>Del</string>
1280+ </property>
1281+ </action>
1282+ <action name="actionGoUp">
1283+ <property name="icon">
1284+ <iconset resource="res.qrc">
1285+ <normaloff>:/resources/resources/go-up.png</normaloff>:/resources/resources/go-up.png</iconset>
1286+ </property>
1287+ <property name="text">
1288+ <string>Up</string>
1289+ </property>
1290+ <property name="toolTip">
1291+ <string>Go parent folder</string>
1292+ </property>
1293+ <property name="shortcut">
1294+ <string>Shift+U</string>
1295+ </property>
1296+ </action>
1297+ <action name="actionGoBack">
1298+ <property name="icon">
1299+ <iconset resource="res.qrc">
1300+ <normaloff>:/resources/resources/go-previous.png</normaloff>:/resources/resources/go-previous.png</iconset>
1301+ </property>
1302+ <property name="text">
1303+ <string>Back</string>
1304+ </property>
1305+ <property name="shortcut">
1306+ <string>Shift+B</string>
1307+ </property>
1308+ </action>
1309+ <action name="actionRename">
1310+ <property name="icon">
1311+ <iconset resource="res.qrc">
1312+ <normaloff>:/resources/resources/edit-rename.png</normaloff>:/resources/resources/edit-rename.png</iconset>
1313+ </property>
1314+ <property name="text">
1315+ <string>Rename...</string>
1316+ </property>
1317+ </action>
1318+ <action name="actionNewFolder">
1319+ <property name="icon">
1320+ <iconset resource="res.qrc">
1321+ <normaloff>:/resources/resources/folder-new.png</normaloff>:/resources/resources/folder-new.png</iconset>
1322+ </property>
1323+ <property name="text">
1324+ <string>NewFolder</string>
1325+ </property>
1326+ </action>
1327+ <action name="actionUndo">
1328+ <property name="enabled">
1329+ <bool>false</bool>
1330+ </property>
1331+ <property name="icon">
1332+ <iconset resource="res.qrc">
1333+ <normaloff>:/resources/resources/undo.png</normaloff>:/resources/resources/undo.png</iconset>
1334+ </property>
1335+ <property name="text">
1336+ <string>Undo</string>
1337+ </property>
1338+ </action>
1339+ <action name="actionEmptyTrash">
1340+ <property name="icon">
1341+ <iconset resource="res.qrc">
1342+ <normaloff>:/resources/resources/empty_trash.png</normaloff>:/resources/resources/empty_trash.png</iconset>
1343+ </property>
1344+ <property name="text">
1345+ <string>EmptyTrash</string>
1346+ </property>
1347+ <property name="toolTip">
1348+ <string>EmptTrash</string>
1349+ </property>
1350+ </action>
1351+ <action name="actionRestoreFromTrash">
1352+ <property name="icon">
1353+ <iconset resource="res.qrc">
1354+ <normaloff>:/resources/resources/recyclebin_full.png</normaloff>:/resources/resources/recyclebin_full.png</iconset>
1355+ </property>
1356+ <property name="text">
1357+ <string>RestoreFromTrash</string>
1358+ </property>
1359+ <property name="toolTip">
1360+ <string>restore From Trash</string>
1361+ </property>
1362+ </action>
1363+ <action name="actionTerminnal">
1364+ <property name="icon">
1365+ <iconset resource="res.qrc">
1366+ <normaloff>:/resources/resources/xterm_48x48.xpm</normaloff>:/resources/resources/xterm_48x48.xpm</iconset>
1367+ </property>
1368+ <property name="text">
1369+ <string>Terminnal</string>
1370+ </property>
1371+ <property name="toolTip">
1372+ <string>open a Terminal</string>
1373+ </property>
1374+ </action>
1375 </widget>
1376- <layoutdefault spacing="6" margin="11"/>
1377- <resources/>
1378+ <resources>
1379+ <include location="res.qrc"/>
1380+ </resources>
1381 <connections/>
1382 </ui>
1383
1384=== added file 'src/plugin/test_folderlistmodel/simpleUI/simpleslots.cpp'
1385--- src/plugin/test_folderlistmodel/simpleUI/simpleslots.cpp 1970-01-01 00:00:00 +0000
1386+++ src/plugin/test_folderlistmodel/simpleUI/simpleslots.cpp 2014-08-13 15:58:44 +0000
1387@@ -0,0 +1,178 @@
1388+/**************************************************************************
1389+ *
1390+ * Copyright 2014 Canonical Ltd.
1391+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
1392+ *
1393+ * This program is free software; you can redistribute it and/or modify
1394+ * it under the terms of the GNU Lesser General Public License as published by
1395+ * the Free Software Foundation; version 3.
1396+ *
1397+ * This program is distributed in the hope that it will be useful,
1398+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1399+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1400+ * GNU Lesser General Public License for more details.
1401+ *
1402+ * You should have received a copy of the GNU Lesser General Public License
1403+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1404+ *
1405+ * File: simpleslots.cpp
1406+ * Date: 21/04/2014
1407+ */
1408+
1409+
1410+#include "simplelist.h"
1411+#include "ui_simplelist.h"
1412+#include "dirmodel.h"
1413+#include "dirselection.h"
1414+#include "placesmodel.h"
1415+#include "terminalfolderapp.h"
1416+
1417+#include <QDir>
1418+#include <QMetaType>
1419+#include <QHeaderView>
1420+#include <QDebug>
1421+#include <QProgressBar>
1422+#include <QMessageBox>
1423+#include <QTimer>
1424+#include <QLineEdit>
1425+#include <QMouseEvent>
1426+
1427+
1428+void SimpleList::onRowClicked(QModelIndex index)
1429+{
1430+ if (index.isValid())
1431+ {
1432+ m_selection->select(index.row(), m_holdingShiftKey, m_holdingCtrlKey);
1433+ }
1434+}
1435+
1436+
1437+void SimpleList::onNewDir()
1438+{
1439+
1440+}
1441+
1442+void SimpleList::onRename()
1443+{
1444+
1445+}
1446+
1447+
1448+
1449+void SimpleList::onSetSort(int col, Qt::SortOrder order)
1450+{
1451+ if (col == 0 || col == 2)
1452+ {
1453+ if (col == 0)
1454+ {
1455+ m_model->setSortBy(DirModel::SortByName);
1456+ }
1457+ else
1458+ {
1459+ m_model->setSortBy(DirModel::SortByDate);
1460+ }
1461+ DirModel::SortOrder o = (DirModel::SortOrder)order;
1462+ m_model->setSortOrder(o);
1463+ }
1464+}
1465+
1466+
1467+void SimpleList::onClipboardChanged()
1468+{
1469+ int clipboardCounter = m_model->getClipboardUrlsCounter();
1470+ statusBar()->showMessage(QString("clipboard items %1")
1471+ .arg(clipboardCounter)
1472+ );
1473+ ui->actionPaste->setEnabled(clipboardCounter > 0);
1474+}
1475+
1476+
1477+void SimpleList::onProgress(int cur, int total, int percent)
1478+{
1479+ QString p;
1480+ m_pbar->setValue(percent);
1481+ if (cur == 0 && percent == 0)
1482+ {
1483+ m_pbar->reset();
1484+ m_pbar->show();
1485+ }
1486+ else
1487+ if (percent == 100)
1488+ {
1489+ QTimer::singleShot(200, m_pbar, SLOT(hide()));
1490+ }
1491+ p.sprintf("progress(cur=%d, total=%d, percent=%d)", cur,total,percent);
1492+ qDebug() << p;
1493+}
1494+
1495+
1496+void SimpleList::onError(QString title, QString message)
1497+{
1498+ if (m_pbar)
1499+ {
1500+ m_pbar->hide();
1501+ }
1502+ QMessageBox::critical(this, title, message);
1503+}
1504+
1505+
1506+void SimpleList::onOpenItem(QModelIndex index)
1507+{
1508+ if (index.isValid())
1509+ {
1510+
1511+ if (!m_model->openIndex(index.row()))
1512+ {
1513+ QModelIndex idx = m_model->index(index.row(), 0);
1514+ QString item = m_model->data(idx).toString();
1515+ onError("Could not open item index", item);
1516+ }
1517+ }
1518+}
1519+
1520+
1521+void SimpleList::onPathChanged(QString path)
1522+{
1523+ if (ui->comboBoxPath->findText(path) == -1)
1524+ {
1525+ ui->comboBoxPath->insertItem(0, path);
1526+ ui->comboBoxPath->setCurrentIndex(0);
1527+ }
1528+ this->setWindowTitle(path);
1529+ allowTrashActions(false);
1530+}
1531+
1532+
1533+void SimpleList::onPathChoosedFromList(int row)
1534+{
1535+ m_model->setPath(ui->comboBoxPath->itemText(row));
1536+}
1537+
1538+
1539+void SimpleList::onPathComboEdited()
1540+{
1541+ m_model->openPath(ui->comboBoxPath->lineEdit()->text());
1542+}
1543+
1544+
1545+void SimpleList::onSelectionChanged(int itemsCounter)
1546+{
1547+ allowSelectedActions(itemsCounter);
1548+}
1549+
1550+
1551+void SimpleList::onPlacesClicked(QModelIndex index)
1552+{
1553+ m_model->setPath(m_placesModel->pathFrom(index.row()));
1554+}
1555+
1556+
1557+void SimpleList::onOpenTerminal()
1558+{
1559+ QString curPath = m_model->path();
1560+ if (!curPath.isEmpty() && !curPath.startsWith("trash:/"))
1561+ {
1562+ TerminalFolderApp terminal;
1563+ terminal.openTerminal(curPath);
1564+ }
1565+}
1566
1567=== modified file 'src/plugin/test_folderlistmodel/simpleUI/simpleui.pro'
1568--- src/plugin/test_folderlistmodel/simpleUI/simpleui.pro 2013-08-24 18:30:29 +0000
1569+++ src/plugin/test_folderlistmodel/simpleUI/simpleui.pro 2014-08-13 15:58:44 +0000
1570@@ -15,10 +15,9 @@
1571
1572 DEFINES += REGRESSION_TEST_FOLDERLISTMODEL
1573
1574-SOURCES += main.cpp\
1575- simplelist.cpp
1576+SOURCES += main.cpp simplelist.cpp simpleslots.cpp placesmodel.cpp terminalfolderapp.cpp
1577
1578-HEADERS += simplelist.h
1579+HEADERS += simplelist.h placesmodel.h terminalfolderapp.h
1580
1581 FORMS += simplelist.ui
1582
1583@@ -28,5 +27,7 @@
1584
1585 DEFINES += SIMULATE_LONG_ACTION DEBUG_EXT_FS_WATCHER
1586
1587+RESOURCES += res.qrc
1588+
1589
1590
1591
1592=== added file 'src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.cpp'
1593--- src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.cpp 1970-01-01 00:00:00 +0000
1594+++ src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.cpp 2014-08-13 15:58:44 +0000
1595@@ -0,0 +1,326 @@
1596+/**************************************************************************
1597+ *
1598+ * Copyright 2013 Canonical Ltd.
1599+ * Copyright 2013 Carlos J Mazieri <carlos.mazieri@gmail.com>
1600+ *
1601+ * You may use this file under the terms of the BSD license as follows:
1602+ *
1603+ * "Redistribution and use in source and binary forms, with or without
1604+ * modification, are permitted provided that the following conditions are
1605+ * met:
1606+ * * Redistributions of source code must retain the above copyright
1607+ * notice, this list of conditions and the following disclaimer.
1608+ * * Redistributions in binary form must reproduce the above copyright
1609+ * notice, this list of conditions and the following disclaimer in
1610+ * the documentation and/or other materials provided with the
1611+ * distribution.
1612+ * * Neither the name of Nemo Mobile nor the names of its contributors
1613+ * may be used to endorse or promote products derived from this
1614+ * software without specific prior written permission.
1615+ *
1616+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1617+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1618+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1619+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1620+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1621+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1622+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1623+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1624+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1625+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1626+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
1627+ *
1628+ * Filename: terminalfolderapp.cpp
1629+ * Created : 29 Jul 2013
1630+ **/
1631+
1632+
1633+#include "terminalfolderapp.h"
1634+
1635+#include <QDir>
1636+#include <QFileInfo>
1637+#include <QDebug>
1638+#include <QCoreApplication>
1639+
1640+#if defined(Q_OS_MSDOS) || defined(Q_OS_WIN)
1641+ // defined WIN Process
1642+#else // Q_OS_UNIX
1643+# include <sys/types.h>
1644+# include <signal.h>
1645+# include <unistd.h>
1646+#endif
1647+
1648+#define DEBUG_MESSAGES 1
1649+
1650+TerminalFolderApp::TerminalFolderApp(QObject *parent) :
1651+ QObject(parent)
1652+{
1653+ findTerminalApp();
1654+}
1655+
1656+TerminalFolderApp::~TerminalFolderApp()
1657+{
1658+}
1659+
1660+
1661+//=======================================================================================================================
1662+/*!
1663+ * \brief TerminalFolderApp::openTerminal() tries to open a terminal
1664+ *
1665+ * It tries to open the terminal application in the sequence:
1666+ * \li "meego-terminal" for Nemo Mobile and Nokia N9
1667+ * \li "ubuntu-terminal-app" for Ubuntu Touch
1668+ * \li "x-terminal-emulator" for any Desktop such as KDE and Gnome
1669+ * \li TERM environment variable if defined
1670+ *
1671+ * \param currentDir
1672+ * \return true if the terminal could be opened
1673+ */
1674+bool TerminalFolderApp::openTerminal(const QString& currentDir)
1675+{
1676+ QFileInfo f(currentDir);
1677+ bool launched = false;
1678+ bool ok = false;
1679+ Q_PID pid = 0;
1680+ if (!m_terminalApp.isEmpty() &&
1681+ f.isDir() &&
1682+ f.isReadable() &&
1683+ f.isExecutable())
1684+ {
1685+ launched = true;
1686+ switch(m_params.count())
1687+ {
1688+ case 2: m_params.append(currentDir); break;
1689+ case 3: m_params[2] = currentDir;
1690+ default: break;
1691+ }
1692+#if DEBUG_MESSAGES
1693+ qDebug() << Q_FUNC_INFO << "starting" << m_terminalApp
1694+ << m_params << "at" << currentDir;
1695+#endif
1696+ ok = QProcess::startDetached(m_terminalApp,
1697+ m_params, currentDir, &pid);
1698+ if (ok)
1699+ {
1700+#if ENABLE_CLOSING
1701+ emit openCounterChanged(m_openPids.count() + 1);
1702+#endif
1703+ m_openPids.append(pid);
1704+ }
1705+ }//end found a terminal application and currentDir is good
1706+#if DEBUG_MESSAGES
1707+ qDebug() << Q_FUNC_INFO << "launched" << launched << "ok" << ok << "returning pid" << pid;
1708+#endif
1709+
1710+ return ok;
1711+}
1712+
1713+
1714+
1715+//=======================================================================================================================
1716+/*!
1717+ * \brief TerminalFolderApp::findTerminalApp() finds a suitable terminal application, called only in the creator
1718+ */
1719+void TerminalFolderApp::findTerminalApp()
1720+{
1721+#if defined(Q_OS_MSDOS) || defined(Q_OS_WIN)
1722+ m_terminalApp = "cmd.exe";
1723+#else // Q_OS_UNIX
1724+ char terminalEnvVar[128];
1725+ terminalEnvVar[0] = 0;
1726+ QByteArray term = qgetenv("TERM");
1727+ if (term.size() > 0)
1728+ {
1729+ ::qstrcpy(terminalEnvVar, term.constData());
1730+ }
1731+
1732+ // Ubuntu Touch
1733+ // appid://com.ubuntu.terminal/terminal/current-user-version"
1734+
1735+
1736+ const char *desktop_terminal_emulator = "x-terminal-emulator";
1737+ const char * apps [] =
1738+ {
1739+ "meego-terminal" // Nemo Mobile and Nokia N9
1740+ ,"ubuntu-terminal-app" // Ubuntu Touch
1741+ ,desktop_terminal_emulator // Desktop (any) KDE/GNOME
1742+ ,terminalEnvVar // TERM environment variable
1743+ };
1744+
1745+ QByteArray usr_bin("/usr/bin");
1746+ QByteArray path = qgetenv("PATH");
1747+ if (path.size() == 0 ) {
1748+ path = usr_bin;
1749+ }
1750+ QList<QByteArray> dirs(path.split(':'));
1751+ if (!dirs.contains(usr_bin)) {
1752+ dirs.append(usr_bin);
1753+ }
1754+ bool found = false;
1755+ for (int counter = 0; !found && counter < dirs.count(); ++counter)
1756+ {
1757+ for(size_t counter2=0 ; !found && counter2 < sizeof(apps)/sizeof(apps[0]); ++counter2)
1758+ {
1759+ if (apps[counter2][0])
1760+ {
1761+ QString terminalPath = dirs[counter];
1762+ terminalPath += QDir::separator();
1763+ terminalPath += apps[counter2];
1764+ QFileInfo terminal(terminalPath);
1765+ if (terminal.exists() && terminal.isExecutable())
1766+ {
1767+ m_terminalApp = terminalPath;
1768+ found = true;
1769+ if (terminalPath.endsWith(QLatin1String(desktop_terminal_emulator)))
1770+ {
1771+ findDesktopParameter();
1772+ }
1773+ }
1774+ }
1775+ }
1776+ }
1777+#if DEBUG_MESSAGES
1778+ qDebug() << Q_FUNC_INFO << m_terminalApp;
1779+#endif
1780+#endif
1781+}
1782+
1783+
1784+//=======================================================================================================================
1785+/*!
1786+ * \brief TerminalFolderApp::findDesktopParameter() sets the working directory parameter
1787+ *
1788+ * Options:
1789+ * \li if konsole --nofork --workdir <dir>
1790+ * \li if gnome-terminal "--disable-factory --working-dir <dir>
1791+ */
1792+void TerminalFolderApp::findDesktopParameter()
1793+{
1794+ QFileInfo app(m_terminalApp);
1795+ int counter = 10;
1796+ while (counter-- && app.isSymLink())
1797+ {
1798+ app.setFile(app.symLinkTarget());
1799+#if DEBUG_MESSAGES
1800+ qDebug() << Q_FUNC_INFO << "testing" << app.fileName();
1801+#endif
1802+ }
1803+ if (app.absoluteFilePath().endsWith(QLatin1String("konsole")))
1804+ {
1805+ m_params.append(QLatin1String("--nofork"));
1806+ m_params.append(QLatin1String("--workdir"));
1807+ if (app.isAbsolute())
1808+ {
1809+ m_terminalApp = app.absoluteFilePath();
1810+ }
1811+ }
1812+ else
1813+ if (app.absoluteFilePath().endsWith(QLatin1String("gnome-terminal")))
1814+ {
1815+ if (app.isAbsolute())
1816+ {
1817+ QFileInfo gnomeTerm(app.absolutePath(),QLatin1String("gnome-terminal"));
1818+ if (gnomeTerm.isExecutable() && gnomeTerm.isFile())
1819+ {
1820+ m_terminalApp = gnomeTerm.absoluteFilePath();
1821+ }
1822+ }
1823+ m_params.append(QLatin1String("--disable-factory"));
1824+ m_params.append(QLatin1String("--working-dir"));
1825+ }
1826+}
1827+
1828+
1829+#if ENABLE_CLOSING
1830+
1831+//=======================================================================================================================
1832+/*!
1833+ * \brief TerminalFolderApp::closeTerminal() tries to close the terminal app
1834+ * \param index index of opened terminals, if more than one.
1835+ * \return true could close the terminal
1836+ */
1837+bool TerminalFolderApp::closeTerminal(int index)
1838+{
1839+ Q_PID pid = 0;
1840+ bool closed = false;
1841+ int counter = m_openPids.count();
1842+ int before = counter;
1843+ while (counter--)
1844+ {
1845+ // check if any terminal that was closed by the user
1846+ pid = m_openPids.at(counter);
1847+ int test = ::kill(pid, 0);
1848+#if DEBUG_MESSAGES
1849+ qDebug() << Q_FUNC_INFO << "pid" << pid
1850+ << "ret from kill" << test;
1851+#endif
1852+ if ( test != 0 )
1853+ {
1854+ m_openPids.takeAt(counter);
1855+ }
1856+ }
1857+#if DEBUG_MESSAGES
1858+ qDebug() << Q_FUNC_INFO << "active terminals" << m_openPids.count();
1859+#endif
1860+ if (index >= 0 && m_openPids.count() > 0)
1861+ {
1862+ if (index >= m_openPids.count())
1863+ {
1864+ index = m_openPids.count() -1;
1865+ }
1866+ pid = m_openPids.takeAt(index);
1867+ if (!(closed = killPid(pid)))
1868+ {
1869+ m_openPids.append(pid);
1870+ }
1871+ }
1872+ if (before != m_openPids.count())
1873+ {
1874+ emit openCounterChanged(m_openPids.count());
1875+ }
1876+ return closed;
1877+}
1878+
1879+
1880+
1881+//=======================================================================================================================
1882+/*!
1883+ kill a process.
1884+
1885+ Tries to kill using SIGTERM which is the default signal to finish a process.
1886+ If the process does not finish then sends a SIGKILL which is equivalment to "kill -9" command
1887+
1888+ \return TRUE the process does not exist anymore (it was successfully killed).
1889+ FALSE could not kill the process
1890+ */
1891+//=======================================================================================================================
1892+bool TerminalFolderApp::killPid(Q_PID pid)
1893+{
1894+ bool processIsNotRunning = true;
1895+ if (::kill(pid, SIGTERM) == 0)
1896+ {
1897+ int counter = 15;
1898+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1899+ while(counter-- && ::kill(pid, 0) == 0)
1900+ {
1901+ ::usleep(50);
1902+ switch(counter)
1903+ {
1904+ case 13: ::kill(pid, SIGKILL); break;
1905+ default: break;
1906+ }
1907+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1908+ }
1909+ if (::kill(pid, 0) == 0)
1910+ {
1911+ processIsNotRunning = false;
1912+ }
1913+ }
1914+#if DEBUG_MESSAGES
1915+ qDebug() << Q_FUNC_INFO << "pid" << pid << "ret" << processIsNotRunning;
1916+#endif
1917+ return processIsNotRunning;
1918+}
1919+
1920+
1921+#endif // ENABLE_CLOSING
1922
1923=== added file 'src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.h'
1924--- src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.h 1970-01-01 00:00:00 +0000
1925+++ src/plugin/test_folderlistmodel/simpleUI/terminalfolderapp.h 2014-08-13 15:58:44 +0000
1926@@ -0,0 +1,100 @@
1927+/**************************************************************************
1928+ *
1929+ * Copyright 2013 Canonical Ltd.
1930+ * Copyright 2013 Carlos J Mazieri <carlos.mazieri@gmail.com>
1931+ *
1932+ * You may use this file under the terms of the BSD license as follows:
1933+ *
1934+ * "Redistribution and use in source and binary forms, with or without
1935+ * modification, are permitted provided that the following conditions are
1936+ * met:
1937+ * * Redistributions of source code must retain the above copyright
1938+ * notice, this list of conditions and the following disclaimer.
1939+ * * Redistributions in binary form must reproduce the above copyright
1940+ * notice, this list of conditions and the following disclaimer in
1941+ * the documentation and/or other materials provided with the
1942+ * distribution.
1943+ * * Neither the name of Nemo Mobile nor the names of its contributors
1944+ * may be used to endorse or promote products derived from this
1945+ * software without specific prior written permission.
1946+ *
1947+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1948+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1949+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1950+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1951+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1952+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1953+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1954+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1955+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1956+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1957+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
1958+ *
1959+ *
1960+ * Filename: terminalfolderapp.h
1961+ * Created : 29 Jul 2013
1962+ **/
1963+
1964+
1965+#ifndef TERMINALFOLDERAPP_H
1966+#define TERMINALFOLDERAPP_H
1967+
1968+#include <QObject>
1969+#include <QProcess>
1970+
1971+
1972+/*!
1973+ * Since KDE and GNOME calling "x-terminal-emulator" do not give the real process id, closing a TerminalFolderApp
1974+ * is disabled by default.
1975+ *
1976+ * \ref TerminalFolderApp::closeTerminal() works for:
1977+ * \li Ubuntu Touch
1978+ * \li Meego, tested on Nemo Mobile and Nokia N9
1979+ */
1980+#ifndef ENABLE_CLOSING
1981+# define ENABLE_CLOSING 0
1982+#endif
1983+
1984+/*!
1985+ * \brief The TerminalFolderApp class opens a suitable Terminal application with a working directory
1986+ *
1987+ * It tries to find and open a terminal application in the sequence:
1988+ * \li "meego-terminal" for Nemo Mobile and Nokia N9
1989+ * \li "ubuntu-terminal-app" for Ubuntu Touch
1990+ * \li "x-terminal-emulator" for any Desktop such as KDE and Gnome
1991+ * \li TERM environment variable if defined
1992+ */
1993+class TerminalFolderApp : public QObject
1994+{
1995+ Q_OBJECT
1996+public:
1997+ explicit TerminalFolderApp(QObject *parent = 0);
1998+ ~TerminalFolderApp();
1999+
2000+public slots:
2001+ bool openTerminal(const QString& currentDir);
2002+
2003+private:
2004+ void findTerminalApp();
2005+ void findDesktopParameter();
2006+
2007+
2008+#if ENABLE_CLOSING
2009+signals:
2010+ void openCounterChanged(int openedTerminals);
2011+public slots:
2012+ bool closeTerminal(int index);
2013+private:
2014+ bool killPid(Q_PID pid);
2015+#endif
2016+
2017+#if REGRESSION_TEST_FOLDERLISTMODEL
2018+public:
2019+#else
2020+private:
2021+#endif
2022+ QList<Q_PID> m_openPids;
2023+ QString m_terminalApp;
2024+ QStringList m_params; //!< used to pass workdir parameter
2025+};
2026+#endif // TERMINALFOLDERAPP_H

Subscribers

People subscribed via source and target branches