Debian Codegraph @

src/plugin/test_folderlistmodel/simpleUI/simpleslots.cpp

raw symbols SCIP
1 /**************************************************************************
2 *
3 * Copyright 2014 Canonical Ltd.
4 * Copyright 2014 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: simpleslots.cpp
19 * Date: 21/04/2014
20 */
21
22
23 #include "simplelist.h"
24 #include "ui_simplelist.h"
25 #include "dirmodel.h"
26 #include "dirselection.h"
27 #include "placesmodel.h"
28 #include "terminalfolderapp.h"
29 #include "ui_authenticationdialog.h"
30
31 #include <QDir>
32 #include <QMetaType>
33 #include <QHeaderView>
34 #include <QDebug>
35 #include <QProgressBar>
36 #include <QMessageBox>
37 #include <QTimer>
38 #include <QLineEdit>
39 #include <QMouseEvent>
40 #include <QDialog>
41
42
43 void SimpleList::onRowClicked(QModelIndex index)
44 {
45 if (index.isValid())
46 {
47 m_selection->select(index.row(), m_holdingShiftKey, m_holdingCtrlKey);
48 }
49 }
50
51
52 void SimpleList::onNewDir()
53 {
54
55 }
56
57 void SimpleList::onRename()
58 {
59
60 }
61
62
63
64 void SimpleList::onSetSort(int col, Qt::SortOrder order)
65 {
66 if (col == 0 || col == 2)
67 {
68 if (col == 0)
69 {
70 m_model->setSortBy(DirModel::SortByName);
71 }
72 else
73 {
74 m_model->setSortBy(DirModel::SortByDate);
75 }
76 DirModel::SortOrder o = (DirModel::SortOrder)order;
77 m_model->setSortOrder(o);
78 }
79 }
80
81
82 void SimpleList::onClipboardChanged()
83 {
84 int clipboardCounter = m_model->getClipboardUrlsCounter();
85 statusBar()->showMessage(QString("clipboard items %1")
86 .arg(clipboardCounter)
87 );
88 ui->actionPaste->setEnabled(clipboardCounter > 0);
89 }
90
91
92 void SimpleList::onProgress(int cur, int total, int percent)
93 {
94 QString p;
95 m_pbar->setValue(percent);
96 if (cur == 0 && percent == 0)
97 {
98 m_pbar->reset();
99 m_pbar->show();
100 }
101 else
102 if (percent == 100)
103 {
104 QTimer::singleShot(200, m_pbar, SLOT(hide()));
105 }
106 p.sprintf("progress(cur=%d, total=%d, percent=%d)", cur,total,percent);
107 qDebug() << p;
108 }
109
110
111 void SimpleList::onError(QString title, QString message)
112 {
113 if (m_pbar)
114 {
115 m_pbar->hide();
116 }
117 QMessageBox::critical(this, title, message);
118 }
119
120
121 void SimpleList::onOpenItem(QModelIndex index)
122 {
123 if (index.isValid())
124 {
125
126 if (!m_model->openIndex(index.row()))
127 {
128 QModelIndex idx = m_model->index(index.row(), 0);
129 QString item = m_model->data(idx).toString();
130 onError("Could not open item index", item);
131 }
132 }
133 }
134
135
136 void SimpleList::onPathChanged(QString path)
137 {
138 int index = ui->comboBoxPath->findText(path);
139 if (index == -1)
140 {
141 ui->comboBoxPath->insertItem(0, path);
142 ui->comboBoxPath->setCurrentIndex(0);
143 }
144 else
145 {
146 ui->comboBoxPath->setCurrentIndex(index);
147 }
148 this->setWindowTitle(path);
149 allowTrashActions(false);
150 }
151
152
153 void SimpleList::onPathChoosedFromList(int row)
154 {
155 m_model->setPath(ui->comboBoxPath->itemText(row));
156 }
157
158
159 void SimpleList::onPathComboEdited()
160 {
161 m_model->openPath(ui->comboBoxPath->lineEdit()->text());
162 }
163
164
165 void SimpleList::onSelectionChanged(int itemsCounter)
166 {
167 allowSelectedActions(itemsCounter);
168 }
169
170
171 void SimpleList::onPlacesClicked(QModelIndex index)
172 {
173 m_model->setPath(m_placesModel->pathFrom(index.row()));
174 }
175
176
177 void SimpleList::onOpenTerminal()
178 {
179 QString curPath = m_model->path();
180 if (!curPath.isEmpty() && !curPath.startsWith("trash:/"))
181 {
182 TerminalFolderApp terminal;
183 terminal.openTerminal(curPath);
184 }
185 }
186
187
188 void SimpleList::onAwaitingResultsChanged()
189 {
190 if (m_model->awaitingResults())
191 {
192 this->setCursor(Qt::BusyCursor);
193 }
194 else
195 {
196 this->setCursor(Qt::ArrowCursor);
197 }
198 }
199
200
201 void SimpleList::onRowsInserted(QModelIndex, int, int)
202 {
203 ui->tableViewFM->resizeColumnToContents(0);
204 }
205
206
207 void SimpleList::onNeedsAutentication(QString user, QString url)
208 {
209 m_uiAuth->lineEditUrl->setText(url);
210 int index = m_uiAuth->comboBoxUser->findText(user);
211 if (index == -1)
212 {
213 m_uiAuth->comboBoxUser->addItem(user);
214 index = m_uiAuth->comboBoxUser->findText(user);
215 }
216 if (index != -1)
217 {
218 m_uiAuth->comboBoxUser->setCurrentIndex(index);
219 }
220 m_uiAuth->checkBox->setChecked(false);
221 if (m_authDialog->exec() == QDialog::Accepted)
222 {
223 QTimer::singleShot(0, this, SLOT(onAuthenticaionAccepted()));
224 }
225 }
226
227
228 void SimpleList::onAuthenticaionAccepted()
229 {
230 m_model->setPath( m_uiAuth->lineEditUrl->text(),
231 m_uiAuth->comboBoxUser->currentText(),
232 m_uiAuth->lineEditPassword->text(),
233 m_uiAuth->checkBox->isChecked() );
234 }