Debian Codegraph @

src/plugin/test_folderlistmodel/simpleUI/simplelist.cpp

raw symbols SCIP
1 /**************************************************************************
2 *
3 * Copyright 2013 Canonical Ltd.
4 * Copyright 2013 Carlos J Mazieri <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * File: simplelist.cpp
19 * Date: 3/9/2013
20 */
21
22 #include "simplelist.h"
23 #include "ui_simplelist.h"
24 #include "dirmodel.h"
25 #include "dirselection.h"
26 #include "placesmodel.h"
27 #include "ui_authenticationdialog.h"
28
29 #include <QDir>
30 #include <QMetaType>
31 #include <QHeaderView>
32 #include <QDebug>
33 #include <QProgressBar>
34 #include <QMessageBox>
35 #include <QTimer>
36 #include <QLineEdit>
37 #include <QMouseEvent>
38 #include <QDialog>
39
40 SimpleList::SimpleList(QWidget *parent) :
41 QMainWindow(parent),
42 ui(new Ui::SimpleList),
43 m_pbar( new QProgressBar() ),
44 m_selection(0),
45 m_holdingCtrlKey(false),
46 m_holdingShiftKey(false),
47 m_button(Qt::NoButton),
48 m_placesModel(new PlacesModel(this)),
49 m_authDialog(new QDialog(this)),
50 m_uiAuth(new Ui::AuthenticationDialog)
51 {
52 //prepare UI
53 ui->setupUi(this);
54 m_uiAuth->setupUi(m_authDialog);
55
56 ui->tableViewFM->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
57 resize(1200,600);
58 m_pbar->setMaximum(100);
59 m_pbar->setMinimum(0);
60
61 ui->listViewPlaces->setModel(m_placesModel);
62 ui->listViewPlaces->setSpacing(ui->listViewPlaces->spacing() + 7);
63
64 //create the model
65 m_model = new DirModel(this);
66 DirModel::registerMetaTypes();
67 ui->tableViewFM->setModel(m_model);
68
69 //enable External Disk Watcher
70 m_model->setEnabledExternalFSWatcher(true);
71 ui->checkBoxExtFsWatcher->setChecked(true);
72
73 //get selection object
74 m_selection = m_model->selectionObject();
75
76 //selection is handled in the model, disable it in the view
77 ui->tableViewFM->setSelectionMode(QAbstractItemView::NoSelection);
78 ui->tableViewFM->viewport()->installEventFilter(this);
79
80 //get default values from model
81 ui->checkBoxShowDirs->setChecked(m_model->showDirectories());
82 ui->checkBoxShowHidden->setChecked(m_model->getShowHiddenFiles());
83 ui->checkBoxShowMediaInfo->setChecked(m_model->readsMediaMetadata());
84 ui->checkBoxMultiSelection->setChecked(m_selection->mode() == DirSelection::Multi);
85
86 //start clibpboard message
87 onClipboardChanged();
88
89 //start with actions disabled,
90 //onSelectionChanged() does a basic actions allowable handling
91 onSelectionChanged(0);
92
93 //connect everything
94 do_connections();
95
96 //start browsing home
97 m_model->goHome();
98 }
99
100
101 SimpleList::~SimpleList()
102 {
103 delete ui;
104 }
105
106
107 bool SimpleList::eventFilter(QObject *obj, QEvent *event)
108 {
109 if (obj == ui->tableViewFM->viewport() && event->type() == QEvent::MouseButtonPress)
110 {
111 QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
112 m_holdingShiftKey = mouseEvent->modifiers() & Qt::ShiftModifier;;
113 m_holdingCtrlKey = mouseEvent->modifiers() & Qt::ControlModifier;;
114 m_button = mouseEvent->button();
115 }
116 return QMainWindow::eventFilter(obj, event);
117 }
118
119
120 void SimpleList::do_connections()
121 {
122 connect(ui->tableViewFM, SIGNAL(clicked(QModelIndex)),
123 this, SLOT(onRowClicked(QModelIndex)));
124
125 connect(ui->tableViewFM, SIGNAL(doubleClicked(QModelIndex)),
126 this, SLOT(onOpenItem(QModelIndex)));
127
128 connect(m_model, SIGNAL(pathChanged(QString)),
129 this, SLOT(onPathChanged(QString)));
130
131 connect(ui->toolButtonUp, SIGNAL(clicked()), m_model, SLOT(cdUp()));
132 connect(ui->toolButtonBack, SIGNAL(clicked()), m_model, SLOT(goBack()));
133 connect(ui->actionCopy, SIGNAL(triggered()), m_model, SLOT(copySelection()));
134 connect(ui->actionCut, SIGNAL(triggered()), m_model, SLOT(cutSelection()));
135 connect(ui->actionDelete, SIGNAL(triggered()), m_model, SLOT(removeSelection()));
136 connect(ui->actionPaste, SIGNAL(triggered()), m_model, SLOT(paste()));
137 connect(ui->actionMoveToTrash,SIGNAL(triggered()), m_model, SLOT(moveSelectionToTrash()));
138 connect(ui->actionTerminal, SIGNAL(triggered()), this, SLOT(onOpenTerminal()));
139
140 connect(ui->actionRestoreFromTrash, SIGNAL(triggered()),
141 m_model, SLOT(restoreSelectionFromTrash()));
142
143 connect(ui->checkBoxShowDirs, SIGNAL(clicked(bool)), m_model, SLOT(setShowDirectories(bool)));
144 connect(ui->checkBoxShowHidden, SIGNAL(clicked(bool)), m_model, SLOT(setShowHiddenFiles(bool)));
145 connect(ui->checkBoxExtFsWatcher, SIGNAL(clicked(bool)), m_model, SLOT(setEnabledExternalFSWatcher(bool)));
146 connect(ui->checkBoxShowMediaInfo, SIGNAL(clicked(bool)),m_model, SLOT(setReadsMediaMetadata(bool)));
147 connect(ui->checkBoxMultiSelection,SIGNAL(clicked(bool)), m_selection, SLOT(setMultiSelection(bool)));
148
149 connect(ui->comboBoxPath, SIGNAL(activated(int)),
150 this, SLOT(onPathChoosedFromList(int)));
151
152 connect(ui->comboBoxPath->lineEdit(), SIGNAL(returnPressed()),
153 this, SLOT(onPathComboEdited()));
154
155 connect(ui->tableViewFM->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
156 this, SLOT(onSetSort(int,Qt::SortOrder)));
157
158 connect(m_model, SIGNAL(progress(int,int,int)),
159 this, SLOT(onProgress(int,int,int)));
160
161 connect(m_model, SIGNAL(clipboardChanged()),
162 this, SLOT(onClipboardChanged()));
163
164 connect(m_model, SIGNAL(error(QString,QString)),
165 this, SLOT(onError(QString,QString)));
166
167 connect(m_model, SIGNAL(awaitingResultsChanged()),
168 this, SLOT(onAwaitingResultsChanged()));
169
170 connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)),
171 this, SLOT(onRowsInserted(QModelIndex,int,int)));
172
173 connect(m_model, SIGNAL(needsAuthentication(QString,QString)),
174 this, SLOT(onNeedsAutentication(QString, QString)));
175
176 connect(m_selection, SIGNAL(selectionChanged(int)),
177 this, SLOT(onSelectionChanged(int)));
178
179 connect(ui->listViewPlaces, SIGNAL(clicked(QModelIndex)),
180 this, SLOT(onPlacesClicked(QModelIndex)));
181
182 }
183
184 //===================================================================
185
186 /*
187 * Simple Allowable methods, they cover not everything
188 *
189 * allowSelectedActions() and allowTrashActions()
190 */
191
192 void SimpleList::allowSelectedActions(int selectedCounter)
193 {
194 bool enableActions = selectedCounter > 0;
195 ui->actionRename->setEnabled(selectedCounter == 1);
196 ui->actionDelete->setEnabled(enableActions);
197 ui->actionCut->setEnabled(enableActions);
198 ui->actionCopy->setEnabled(enableActions);
199 allowTrashActions(enableActions);
200 }
201
202
203 void SimpleList::allowTrashActions(bool enable)
204 {
205 if (m_model->path().startsWith("trash:/"))
206 {
207 ui->actionEmptyTrash->setEnabled(true);
208 ui->actionRestoreFromTrash->setEnabled(enable);
209 ui->actionMoveToTrash->setEnabled(false);
210 ui->actionNewFolder->setEnabled(false);
211 ui->actionTerminal->setEnabled(false);
212 }
213 else
214 {
215 ui->actionEmptyTrash->setEnabled(false);
216 ui->actionRestoreFromTrash->setEnabled(false);
217 ui->actionMoveToTrash->setEnabled(enable);
218 ui->actionNewFolder->setEnabled(true);
219 ui->actionTerminal->setEnabled(true);
220 }
221 }