Commit 4da778df authored by Laurent Montel's avatar Laurent Montel 😁

Coding style

parent 66fba87b
...@@ -35,18 +35,18 @@ ...@@ -35,18 +35,18 @@
#include "kquery.h" #include "kquery.h"
#include "kfindtreeview.h" #include "kfindtreeview.h"
KfindDlg::KfindDlg(const QUrl & url, QWidget *parent) KfindDlg::KfindDlg(const QUrl &url, QWidget *parent)
: KDialog( parent ) : KDialog(parent)
{ {
setButtons( User1 | User2 | User3 | Close | Help ); setButtons(User1 | User2 | User3 | Close | Help);
setDefaultButton( User3 ); setDefaultButton(User3);
setModal( true ); setModal(true);
setButtonGuiItem( User3, KStandardGuiItem::find()); setButtonGuiItem(User3, KStandardGuiItem::find());
setButtonGuiItem( User2, KStandardGuiItem::stop() ); setButtonGuiItem(User2, KStandardGuiItem::stop());
setButtonGuiItem( User1, KStandardGuiItem::saveAs() ); setButtonGuiItem(User1, KStandardGuiItem::saveAs());
QWidget::setWindowTitle( i18nc("@title:window", "Find Files/Folders" ) ); QWidget::setWindowTitle(i18nc("@title:window", "Find Files/Folders"));
setButtonsOrientation(Qt::Vertical); setButtonsOrientation(Qt::Vertical);
enableButton(User3, true); // Enable "Find" enableButton(User3, true); // Enable "Find"
...@@ -56,11 +56,11 @@ KfindDlg::KfindDlg(const QUrl & url, QWidget *parent) ...@@ -56,11 +56,11 @@ KfindDlg::KfindDlg(const QUrl & url, QWidget *parent)
isResultReported = false; isResultReported = false;
QFrame *frame = new QFrame; QFrame *frame = new QFrame;
setMainWidget( frame ); setMainWidget(frame);
// create tabwidget // create tabwidget
tabWidget = new KfindTabWidget( frame ); tabWidget = new KfindTabWidget(frame);
tabWidget->setURL( url ); tabWidget->setURL(url);
tabWidget->setFocus(); tabWidget->setFocus();
// prepare window for find results // prepare window for find results
...@@ -68,7 +68,7 @@ KfindDlg::KfindDlg(const QUrl & url, QWidget *parent) ...@@ -68,7 +68,7 @@ KfindDlg::KfindDlg(const QUrl & url, QWidget *parent)
mStatusBar = new KStatusBar(frame); mStatusBar = new KStatusBar(frame);
mStatusBar->insertItem(QStringLiteral("AMiddleLengthText..."), 0); mStatusBar->insertItem(QStringLiteral("AMiddleLengthText..."), 0);
setStatusMsg( i18nc("the application is currently idle, there is no active search", "Idle.") ); setStatusMsg(i18nc("the application is currently idle, there is no active search", "Idle."));
mStatusBar->setItemAlignment(0, Qt::AlignLeft | Qt::AlignVCenter); mStatusBar->setItemAlignment(0, Qt::AlignLeft | Qt::AlignVCenter);
mStatusBar->insertPermanentItem(QString(), 1, 1); mStatusBar->insertPermanentItem(QString(), 1, 1);
mStatusBar->setItemAlignment(1, Qt::AlignRight | Qt::AlignVCenter); mStatusBar->setItemAlignment(1, Qt::AlignRight | Qt::AlignVCenter);
...@@ -87,18 +87,18 @@ KfindDlg::KfindDlg(const QUrl & url, QWidget *parent) ...@@ -87,18 +87,18 @@ KfindDlg::KfindDlg(const QUrl & url, QWidget *parent)
connect(this, SIGNAL(user1Clicked()), connect(this, SIGNAL(user1Clicked()),
win, SLOT(saveResults())); win, SLOT(saveResults()));
connect( this, SIGNAL(closeClicked()), this, SLOT(finishAndClose()) ); connect(this, SIGNAL(closeClicked()), this, SLOT(finishAndClose()));
connect(win ,SIGNAL(resultSelected(bool)), connect(win, SIGNAL(resultSelected(bool)),
this,SIGNAL(resultSelected(bool))); this, SIGNAL(resultSelected(bool)));
query = new KQuery(frame); query = new KQuery(frame);
connect(query, SIGNAL(result(int)), SLOT(slotResult(int))); connect(query, SIGNAL(result(int)), SLOT(slotResult(int)));
connect(query, SIGNAL(foundFileList(QList<QPair<KFileItem,QString> >)), SLOT(addFiles(QList<QPair<KFileItem,QString> >))); connect(query, SIGNAL(foundFileList(QList<QPair<KFileItem,QString> >)), SLOT(addFiles(QList<QPair<KFileItem,QString> >)));
KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true); KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
setButtonMenu( Help, helpMenu->menu() ); setButtonMenu(Help, helpMenu->menu());
dirwatch=NULL; dirwatch = NULL;
} }
KfindDlg::~KfindDlg() KfindDlg::~KfindDlg()
...@@ -125,7 +125,6 @@ void KfindDlg::setStatusMsg(const QString &msg) ...@@ -125,7 +125,6 @@ void KfindDlg::setStatusMsg(const QString &msg)
mStatusBar->changeItem(msg, 0); mStatusBar->changeItem(msg, 0);
} }
void KfindDlg::startSearch() void KfindDlg::startSearch()
{ {
tabWidget->setQuery(query); tabWidget->setQuery(query);
...@@ -143,7 +142,7 @@ void KfindDlg::startSearch() ...@@ -143,7 +142,7 @@ void KfindDlg::startSearch()
enableButton(User1, false); // Disable "Save As..." enableButton(User1, false); // Disable "Save As..."
delete dirwatch; delete dirwatch;
dirwatch=new KDirWatch(); dirwatch = new KDirWatch();
connect(dirwatch, SIGNAL(created(QString)), this, SLOT(slotNewItems(QString))); connect(dirwatch, SIGNAL(created(QString)), this, SLOT(slotNewItems(QString)));
connect(dirwatch, SIGNAL(deleted(QString)), this, SLOT(slotDeleteItem(QString))); connect(dirwatch, SIGNAL(deleted(QString)), this, SLOT(slotDeleteItem(QString)));
dirwatch->addDir(query->url().toLocalFile(), KDirWatch::WatchFiles); dirwatch->addDir(query->url().toLocalFile(), KDirWatch::WatchFiles);
...@@ -161,11 +160,11 @@ void KfindDlg::startSearch() ...@@ -161,11 +160,11 @@ void KfindDlg::startSearch()
// been fixed in KDirWatch, but that has not yet been confirmed. // been fixed in KDirWatch, but that has not yet been confirmed.
//Getting a list of all subdirs //Getting a list of all subdirs
if(tabWidget->isSearchRecursive() && (dirwatch->internalMethod() == KDirWatch::FAM)) if (tabWidget->isSearchRecursive() && (dirwatch->internalMethod() == KDirWatch::FAM)) {
{ const QStringList subdirs = getAllSubdirs(query->url().path());
const QStringList subdirs=getAllSubdirs(query->url().path()); for (QStringList::const_iterator it = subdirs.constBegin(); it != subdirs.constEnd(); ++it) {
for(QStringList::const_iterator it = subdirs.constBegin(); it != subdirs.constEnd(); ++it) dirwatch->addDir(*it, true);
dirwatch->addDir(*it,true); }
} }
#endif #endif
...@@ -196,25 +195,20 @@ void KfindDlg::newSearch() ...@@ -196,25 +195,20 @@ void KfindDlg::newSearch()
void KfindDlg::slotResult(int errorCode) void KfindDlg::slotResult(int errorCode)
{ {
if (errorCode == 0) if (errorCode == 0) {
setStatusMsg( i18nc("the application is currently idle, there is no active search", "Idle.") ); setStatusMsg(i18nc("the application is currently idle, there is no active search", "Idle."));
else if (errorCode == KIO::ERR_USER_CANCELED) } else if (errorCode == KIO::ERR_USER_CANCELED) {
setStatusMsg(i18n("Canceled.")); setStatusMsg(i18n("Canceled."));
else if (errorCode == KIO::ERR_MALFORMED_URL) } else if (errorCode == KIO::ERR_MALFORMED_URL) {
{
setStatusMsg(i18n("Error.")); setStatusMsg(i18n("Error."));
KMessageBox::sorry( this, i18n("Please specify an absolute path in the \"Look in\" box.")); KMessageBox::sorry(this, i18n("Please specify an absolute path in the \"Look in\" box."));
} } else if (errorCode == KIO::ERR_DOES_NOT_EXIST) {
else if (errorCode == KIO::ERR_DOES_NOT_EXIST)
{
setStatusMsg(i18n("Error.")); setStatusMsg(i18n("Error."));
KMessageBox::sorry( this, i18n("Could not find the specified folder.")); KMessageBox::sorry(this, i18n("Could not find the specified folder."));
} } else {
else
{
//qDebug()<<"KIO error code: "<<errorCode; //qDebug()<<"KIO error code: "<<errorCode;
setStatusMsg(i18n("Error.")); setStatusMsg(i18n("Error."));
}; }
enableButton(User3, true); // Enable "Find" enableButton(User3, true); // Enable "Find"
enableButton(User2, false); // Disable "Stop" enableButton(User2, false); // Disable "Stop"
...@@ -223,21 +217,19 @@ void KfindDlg::slotResult(int errorCode) ...@@ -223,21 +217,19 @@ void KfindDlg::slotResult(int errorCode)
win->endSearch(); win->endSearch();
tabWidget->endSearch(); tabWidget->endSearch();
setFocus(); setFocus();
} }
void KfindDlg::addFiles( const QList< QPair<KFileItem,QString> > & pairs) void KfindDlg::addFiles(const QList< QPair<KFileItem, QString> > &pairs)
{ {
win->insertItems( pairs ); win->insertItems(pairs);
if (!isResultReported) if (!isResultReported) {
{
emit haveResults(true); emit haveResults(true);
isResultReported = true; isResultReported = true;
} }
QString str = i18np("one file found", "%1 files found", win->itemCount()); QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg( str ); setProgressMsg(str);
} }
void KfindDlg::setFocus() void KfindDlg::setFocus()
...@@ -250,31 +242,31 @@ void KfindDlg::copySelection() ...@@ -250,31 +242,31 @@ void KfindDlg::copySelection()
win->copySelection(); win->copySelection();
} }
void KfindDlg::about () void KfindDlg::about()
{ {
KAboutApplicationDialog dlg(KAboutData::applicationData(), 0, this); KAboutApplicationDialog dlg(KAboutData::applicationData(), 0, this);
dlg.exec (); dlg.exec();
} }
void KfindDlg::slotDeleteItem(const QString& file) void KfindDlg::slotDeleteItem(const QString &file)
{ {
//qDebug()<<QString("Will remove one item: %1").arg(file); //qDebug()<<QString("Will remove one item: %1").arg(file);
win->removeItem( QUrl::fromLocalFile(file) ); win->removeItem(QUrl::fromLocalFile(file));
QString str = i18np("one file found", "%1 files found", win->itemCount()); QString str = i18np("one file found", "%1 files found", win->itemCount());
setProgressMsg( str ); setProgressMsg(str);
} }
void KfindDlg::slotNewItems( const QString& file ) void KfindDlg::slotNewItems(const QString &file)
{ {
//qDebug()<<QString("Will add this item") << file; //qDebug()<<QString("Will add this item") << file;
const QUrl url = QUrl::fromLocalFile(file); const QUrl url = QUrl::fromLocalFile(file);
if( query->url().isParentOf(url) ) if (query->url().isParentOf(url)) {
{ if (!win->isInserted(url)) {
if ( !win->isInserted( url ) ) query->slotListEntries(QStringList() << file);
query->slotListEntries( QStringList() << file ); }
} }
} }
...@@ -283,15 +275,15 @@ QStringList KfindDlg::getAllSubdirs(QDir d) ...@@ -283,15 +275,15 @@ QStringList KfindDlg::getAllSubdirs(QDir d)
QStringList dirs; QStringList dirs;
QStringList subdirs; QStringList subdirs;
d.setFilter( QDir::Dirs ); d.setFilter(QDir::Dirs);
dirs = d.entryList(); dirs = d.entryList();
for(QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it) for (QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it) {
{ if ((*it == QLatin1String(".")) || (*it == QLatin1String(".."))) {
if((*it==QLatin1String(".")) || (*it==QLatin1String("..")))
continue; continue;
}
subdirs.append(d.path()+QLatin1Char('/')+*it); subdirs.append(d.path()+QLatin1Char('/')+*it);
subdirs+=getAllSubdirs(QString(d.path()+QLatin1Char('/')+*it)); subdirs += getAllSubdirs(QString(d.path()+QLatin1Char('/')+*it));
} }
return subdirs; return subdirs;
} }
...@@ -35,12 +35,12 @@ class KfindTabWidget; ...@@ -35,12 +35,12 @@ class KfindTabWidget;
class KFindTreeView; class KFindTreeView;
class KStatusBar; class KStatusBar;
class KfindDlg: public KDialog class KfindDlg : public KDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit KfindDlg(const QUrl & url, QWidget * parent = 0); explicit KfindDlg(const QUrl &url, QWidget *parent = 0);
~KfindDlg(); ~KfindDlg();
void copySelection(); void copySelection();
...@@ -55,13 +55,13 @@ public Q_SLOTS: ...@@ -55,13 +55,13 @@ public Q_SLOTS:
void startSearch(); void startSearch();
void stopSearch(); void stopSearch();
void newSearch(); void newSearch();
void addFiles( const QList< QPair<KFileItem,QString> > & ); void addFiles(const QList< QPair<KFileItem, QString> > &);
void setFocus(); void setFocus();
void slotResult(int); void slotResult(int);
// void slotSearchDone(); // void slotSearchDone();
void about (); void about();
void slotDeleteItem(const QString&); void slotDeleteItem(const QString &);
void slotNewItems( const QString& ); void slotNewItems(const QString &);
void finishAndClose(); void finishAndClose();
...@@ -71,7 +71,7 @@ Q_SIGNALS: ...@@ -71,7 +71,7 @@ Q_SIGNALS:
private: private:
KfindTabWidget *tabWidget; KfindTabWidget *tabWidget;
KFindTreeView * win; KFindTreeView *win;
bool isResultReported; bool isResultReported;
KQuery *query; KQuery *query;
......
This diff is collapsed.
...@@ -38,15 +38,22 @@ class KfindDlg; ...@@ -38,15 +38,22 @@ class KfindDlg;
class KFindItem class KFindItem
{ {
public: public:
explicit KFindItem( const KFileItem & = KFileItem(), const QString & subDir = QString(), const QString & matchingLine = QString() ); explicit KFindItem(const KFileItem & = KFileItem(), const QString &subDir = QString(), const QString &matchingLine = QString());
QVariant data(int column, int role) const; QVariant data(int column, int role) const;
KFileItem getFileItem() const { return m_fileItem; } KFileItem getFileItem() const
bool isValid() const { return !m_fileItem.isNull(); } {
return m_fileItem;
}
private: bool isValid() const
{
return !m_fileItem.isNull();
}
private:
KFileItem m_fileItem; KFileItem m_fileItem;
QString m_matchingLine; QString m_matchingLine;
QString m_subDir; QString m_subDir;
...@@ -54,79 +61,98 @@ class KFindItem ...@@ -54,79 +61,98 @@ class KFindItem
QIcon m_icon; QIcon m_icon;
}; };
class KFindItemModel: public QAbstractTableModel class KFindItemModel : public QAbstractTableModel
{ {
public: public:
KFindItemModel( KFindTreeView* parent); KFindItemModel(KFindTreeView *parent);
void insertFileItems( const QList< QPair<KFileItem,QString> > &); void insertFileItems(const QList< QPair<KFileItem, QString> > &);
void removeItem(const QUrl &); void removeItem(const QUrl &);
bool isInserted(const QUrl &); bool isInserted(const QUrl &);
void clear(); void clear();
Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE { return Qt::CopyAction | Qt::MoveAction; } Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt::ItemFlags flags(const QModelIndex &) const Q_DECL_OVERRIDE; Qt::ItemFlags flags(const QModelIndex &) const Q_DECL_OVERRIDE;
QMimeData * mimeData(const QModelIndexList &) const Q_DECL_OVERRIDE; QMimeData *mimeData(const QModelIndexList &) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE
{
Q_UNUSED(parent);
return 6;
}
int columnCount ( const QModelIndex & parent = QModelIndex() ) const Q_DECL_OVERRIDE { Q_UNUSED(parent); return 6; } int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int rowCount ( const QModelIndex & parent = QModelIndex() ) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
KFindItem itemAtIndex( const QModelIndex & index ) const; KFindItem itemAtIndex(const QModelIndex &index) const;
QList<KFindItem> getItemList() const { return m_itemList; } QList<KFindItem> getItemList() const
{
return m_itemList;
}
private: private:
QList<KFindItem> m_itemList; QList<KFindItem> m_itemList;
KFindTreeView* m_view; KFindTreeView *m_view;
}; };
class KFindSortFilterProxyModel: public QSortFilterProxyModel class KFindSortFilterProxyModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
KFindSortFilterProxyModel(QObject * parent = 0): KFindSortFilterProxyModel(QObject *parent = 0)
QSortFilterProxyModel(parent){} : QSortFilterProxyModel(parent)
{
}
protected: protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE; bool lessThan(const QModelIndex &left, const QModelIndex &right) const Q_DECL_OVERRIDE;
}; };
class KFindTreeView: public QTreeView class KFindTreeView : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
KFindTreeView( QWidget * parent, KfindDlg * findDialog); KFindTreeView(QWidget *parent, KfindDlg *findDialog);
~KFindTreeView(); ~KFindTreeView();
void beginSearch(const QUrl& baseUrl); void beginSearch(const QUrl &baseUrl);
void endSearch(); void endSearch();
void insertItems(const QList< QPair<KFileItem,QString> > &); void insertItems(const QList< QPair<KFileItem, QString> > &);
void removeItem(const QUrl & url); void removeItem(const QUrl &url);
bool isInserted(const QUrl &url)
{
return m_model->isInserted(url);
}
bool isInserted(const QUrl & url) { return m_model->isInserted( url ); } QString reducedDir(const QString &fullDir);
QString reducedDir(const QString& fullDir); int itemCount()
{
return m_model->rowCount();
}
int itemCount() { return m_model->rowCount(); }
QList<QUrl> selectedUrls(); QList<QUrl> selectedUrls();
public Q_SLOTS: public Q_SLOTS:
void copySelection(); void copySelection();
void contextMenuRequested( const QPoint & p ); void contextMenuRequested(const QPoint &p);
private Q_SLOTS: private Q_SLOTS:
void deleteSelectedFiles(); void deleteSelectedFiles();
void moveToTrashSelectedFiles(); void moveToTrashSelectedFiles();
void slotExecute( const QModelIndex & index ); void slotExecute(const QModelIndex &index);
void slotExecuteSelected(); void slotExecuteSelected();
void openContainingFolder(); void openContainingFolder();
...@@ -135,25 +161,28 @@ class KFindTreeView: public QTreeView ...@@ -135,25 +161,28 @@ class KFindTreeView: public QTreeView
void reconfigureMouseSettings(); void reconfigureMouseSettings();
void updateMouseButtons(); void updateMouseButtons();
protected: protected:
void dragMoveEvent( QDragMoveEvent *e ) Q_DECL_OVERRIDE { e->accept(); } void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE
{
e->accept();
}
Q_SIGNALS: Q_SIGNALS:
void resultSelected(bool); void resultSelected(bool);
private: private:
void resizeToContents(); void resizeToContents();
QDir m_baseDir; QDir m_baseDir;
KFindItemModel * m_model; KFindItemModel *m_model;
KFindSortFilterProxyModel * m_proxyModel; KFindSortFilterProxyModel *m_proxyModel;
KActionCollection * m_actionCollection; KActionCollection *m_actionCollection;
QMenu * m_contextMenu; QMenu *m_contextMenu;
Qt::MouseButtons m_mouseButtons; Qt::MouseButtons m_mouseButtons;
KfindDlg * m_kfindDialog; KfindDlg *m_kfindDialog;
}; };
#endif #endif
This diff is collapsed.
...@@ -42,16 +42,16 @@ class QLabel; ...@@ -42,16 +42,16 @@ class QLabel;
class KfDirDialog; class KfDirDialog;
class KfindTabWidget: public KTabWidget class KfindTabWidget : public KTabWidget
{ {
Q_OBJECT