1
/**************************************************************************
3
* Copyright 2013 Canonical Ltd.
4
* Copyright 2013 Carlos J Mazieri <carlos.mazieri@gmail.com>
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.
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.
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/>.
18
* File: simplelist.cpp
22
#include "simplelist.h"
23
#include "ui_simplelist.h"
28
#include <QHeaderView>
30
#include <QProgressBar>
31
#include <QMessageBox>
34
SimpleList::SimpleList(QWidget *parent) :
36
ui(new Ui::SimpleList),
38
m_pbar( new QProgressBar() )
42
m_model = new DirModel(this);
44
DirModel::registerMetaTypes();
45
ui->tableView->setModel(m_model);
47
connect(ui->tableView, SIGNAL(clicked(QModelIndex)),
48
this, SLOT(onRowClicked(QModelIndex)));
49
connect(ui->tableView, SIGNAL(doubleClicked(QModelIndex)),
50
this, SLOT(onOpenItem(QModelIndex)));
52
connect(ui->tableView->verticalHeader(), SIGNAL(sectionClicked(int)),
53
this, SLOT(onVerticalHeaderClicked(int)));
55
connect(m_model, SIGNAL(pathChanged(QString)),
56
this, SLOT(pathChanged(QString)));
58
connect(ui->pushButtonCdUp, SIGNAL(clicked()), this, SLOT(onCdUP()));
59
connect(ui->pushButtonCopy, SIGNAL(clicked()), this, SLOT(onCopy()));
60
connect(ui->pushButtonCut, SIGNAL(clicked()), this, SLOT(onCut()));
61
connect(ui->pushButtonDelete, SIGNAL(clicked()), this, SLOT(onRemove()));
62
connect(ui->pushButtonGoHome, SIGNAL(clicked()), this, SLOT(onGoHome()));
63
connect(ui->pushButtonIntoDirs,SIGNAL(clicked()), this, SLOT(onCdInto()));
64
connect(ui->pushButtonNewDir, SIGNAL(clicked()), this, SLOT(onNewDir()));
65
connect(ui->pushButtonPaste, SIGNAL(clicked()), this, SLOT(onPaste()));
66
connect(ui->pushButtonRename, SIGNAL(clicked()), this, SLOT(onRename()));
68
connect(ui->checkBoxShowDirs, SIGNAL(clicked(bool)), this, SLOT(onShowDirs(bool)));
69
connect(ui->checkBoxShowHidden, SIGNAL(clicked(bool)), this, SLOT(onShowHidden(bool)));
70
connect(ui->checkBoxExtFsWatcher, SIGNAL(toggled(bool)),this, SLOT(onExtFsWatcherEnabled(bool)));
72
connect(ui->pushButtonOpen, SIGNAL(clicked()),
73
this, SLOT(onOpen()));
75
connect(ui->lineEditOpen, SIGNAL(returnPressed()),
76
this, SLOT(onOpen()));
78
ui->checkBoxShowDirs->setChecked( m_model->showDirectories() );
82
connect(m_model, SIGNAL(insertedRow(int)),
83
this, SLOT(resizeColumnForName(int)));
85
connect(ui->tableView->horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
86
this, SLOT(setSort(int,Qt::SortOrder)));
88
connect(m_model, SIGNAL(progress(int,int,int)),
89
this, SLOT(progress(int,int,int)));
91
connect(m_model, SIGNAL(clipboardChanged()),
92
this, SLOT(clipboardChanged()));
94
connect(m_model, SIGNAL(error(QString,QString)),
95
this, SLOT(error(QString,QString)));
97
ui->tableView->horizontalHeader()->setSortIndicator(0,Qt::AscendingOrder);
99
m_pbar->setMaximum(100);
100
m_pbar->setMinimum(0);
102
m_model->setReadsMediaMetadata(true);
103
ui->checkBoxExtFsWatcher->click();
109
SimpleList::~SimpleList()
114
void SimpleList::onRowClicked(QModelIndex index)
118
m_curRow = index.row();
127
void SimpleList::onCdInto()
129
m_model->cdIntoIndex(m_curRow);
132
void SimpleList::onGoHome()
137
void SimpleList::onCdUP()
142
void SimpleList::onRemove()
144
m_model->removeIndex(m_curRow);
147
void SimpleList::onCopy()
149
m_model->copyIndex(m_curRow);
152
void SimpleList::onCut()
154
m_model->cutIndex(m_curRow);
158
void SimpleList::onPaste()
163
void SimpleList::onNewDir()
165
m_model->mkdir(ui->lineEditNewDir->text());
168
void SimpleList::onRename()
170
m_model->rename(m_curRow, ui->lineEditRename->text());
173
void SimpleList::onShowDirs(bool show)
175
m_model->setShowDirectories(show);
178
void SimpleList::onShowHidden(bool s)
180
m_model->setShowHiddenFiles(s);
183
void SimpleList::onVerticalHeaderClicked(int row)
189
void SimpleList::setSort(int col, Qt::SortOrder order)
191
if (col == 0 || col == 2)
195
m_model->setSortBy(DirModel::SortByName);
199
m_model->setSortBy(DirModel::SortByDate);
201
DirModel::SortOrder o = (DirModel::SortOrder)order;
202
m_model->setSortOrder(o);
206
void SimpleList::clipboardChanged()
208
ui->clipboardNumber->setText( QString::number(m_model->getClipboardUrlsCounter()));
211
void SimpleList::progress(int cur, int total, int percent)
214
m_pbar->setValue(percent);
215
if (cur == 0 && percent == 0)
223
QTimer::singleShot(200, m_pbar, SLOT(hide()));
225
p.sprintf("progress(cur=%d, total=%d, percent=%d)", cur,total,percent);
230
void SimpleList::error(QString title, QString message)
236
QMessageBox::critical(this, title, message);
239
void SimpleList::onOpenItem(QModelIndex index)
243
m_curRow = index.row();
244
if (!m_model->openIndex(m_curRow))
246
QModelIndex idx = m_model->index(m_curRow, 0);
247
QString item = m_model->data(idx).toString();
248
error("Could not open item index", item);
258
void SimpleList::pathChanged(QString path)
260
this->setWindowTitle(path);
263
void SimpleList::resizeColumnForName(int)
265
ui->tableView->resizeColumnToContents(0);
269
void SimpleList::onOpen()
271
if ( ! m_model->openPath(ui->lineEditOpen->text()) )
273
QMessageBox::critical(this, "DirModel::openIndex() failed to open" , ui->lineEditOpen->text());
278
void SimpleList::onExtFsWatcherEnabled(bool enable)
280
m_model->setEnabledExternalFSWatcher(enable);