From 0f724eb1463c5bb87d04ebed32ea33d2d6e460ae Mon Sep 17 00:00:00 2001 From: Petr Vanek Date: Tue, 15 Oct 2013 05:52:42 +0200 Subject: [PATCH 1/5] build fixes: build options moved into the beginning of main cmake file;link directories for enca when it's located in non-standard path --- CMakeLists.txt | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6bb1472..09963e17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,16 @@ project (juffed) cmake_minimum_required (VERSION 2.6.0) - if (COMMAND cmake_policy) - CMAKE_POLICY (SET CMP0003 NEW) - endif (COMMAND cmake_policy) + + +# build options +option(USE_SYSTEM_QTSINGLEAPPLICATION "Try to find system-wide QtSingleApplication library" OFF) +option(USE_ENCA "Try to find Enca library for file encoding check" ON) + + +if (COMMAND cmake_policy) + CMAKE_POLICY (SET CMP0003 NEW) +endif (COMMAND cmake_policy) set ( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH} ) set ( PREFIX ${CMAKE_INSTALL_PREFIX} ) @@ -100,7 +107,6 @@ find_package ( QScintilla2 REQUIRED) include ( cmake/FileSets.cmake ) include ( cmake/SomeLexers.cmake ) -option(USE_SYSTEM_QTSINGLEAPPLICATION "" OFF) if(USE_SYSTEM_QTSINGLEAPPLICATION) find_package ( QtSingleApplication REQUIRED) else(USE_SYSTEM_QTSINGLEAPPLICATION) @@ -149,15 +155,20 @@ QT4_ADD_TRANSLATION ( juffed_QM ${juffed_TS} ) include(FindPkgConfig) +if (USE_ENCA) # try to find libenca - optional pkg_check_modules(ENCA enca) if (ENCA_FOUND) add_definitions(-DHAVE_ENCA) include_directories(${ENCA_INCLUDE_DIRS}) + link_directories(${ENCA_LIBRARY_DIRS}) + message(STATUS "Enca includes: ${ENCA_INCLUDE_DIRS}") + message(STATUS "Enca library dir: ${ENCA_LIBRARY_DIRS}") + message(STATUS "Enca library: ${ENCA_LIBRARIES}") else (ENCA_FOUND) message(WARNING "No enca library found. Building without auto-language-detection") endif (ENCA_FOUND) - +endif (USE_ENCA) # include directories @@ -190,6 +201,9 @@ add_library ( ${JUFFLIB} SHARED target_link_libraries ( ${JUFFLIB} ${QT_LIBRARIES} ) +if (ENCA_FOUND) + target_link_libraries( ${JUFFLIB} ${ENCA_LIBRARIES} ) +endif (ENCA_FOUND) add_library ( ${QSCI_ENGINE} SHARED ${juffed_qsci_SRCS} @@ -207,7 +221,7 @@ target_link_libraries ( ${QSCI_ENGINE} if (APPLE) message ( STATUS "Building as an apple bundle" ) set ( APPLE_PREFIX "${CMAKE_INSTALL_PREFIX}/${JUFFED}.app/Contents" ) - + add_definitions(-DAPPLEBUNDLE) set(GUI_TYPE MACOSX_BUNDLE) # create Info.plist file @@ -277,9 +291,6 @@ target_link_libraries ( ${JUFFED} ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} ) -if (ENCA_FOUND) - target_link_libraries( ${JUFFED} ${ENCA_LIBRARIES} ) -endif (ENCA_FOUND) if ( UNIX ) set(CMAKE_CXX_FLAGS "-Wall -Wextra") From f09e79191f36fd71523b4cb057acf1a8bbe078f8 Mon Sep 17 00:00:00 2001 From: Petr Vanek Date: Tue, 15 Oct 2013 06:59:10 +0200 Subject: [PATCH 2/5] main window restore: use save/restore geometry methods instead setGemotery/geometry as the original solution does not work correctly on OS X (and wayland probably); unused MW event handlers commented out --- include/MainSettings.h | 4 ++-- src/app/JuffEd.cpp | 6 +----- src/app/ui/JuffMW.cpp | 42 +++++++++++++++++++++------------------- src/app/ui/JuffMW.h | 6 +++--- src/lib/MainSettings.cpp | 9 +++++---- src/lib/Settings.cpp | 2 +- 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/include/MainSettings.h b/include/MainSettings.h index deba51a0..30eb639f 100644 --- a/include/MainSettings.h +++ b/include/MainSettings.h @@ -59,13 +59,13 @@ class LIBJUFF_EXPORT MainSettings { static void set(IntKey, int); static void set(BoolKey, bool); static void set(StringKey, const QString&); - static void setGeometry(const QRect&); + static void saveGeometry(const QByteArray&); static void setMwState(const QByteArray&); static int get(IntKey); static bool get(BoolKey); static QString get(StringKey); - static QRect geometry(); + static QByteArray restoreGeometry(); static QByteArray mwState(); // static QColor get(ColorKey); }; diff --git a/src/app/JuffEd.cpp b/src/app/JuffEd.cpp index 1cb2c51b..6d5a2ac8 100644 --- a/src/app/JuffEd.cpp +++ b/src/app/JuffEd.cpp @@ -79,11 +79,7 @@ JuffEd::JuffEd() : Juff::PluginNotifier(), Juff::DocHandlerInt() { onSettingsApplied(); - mw_->setGeometry(MainSettings::geometry()); - if ( MainSettings::get(MainSettings::Maximized) ) { - mw_->showMaximized(); - } - mw_->restoreState(); + mw_->restoreState(); } JuffEd::~JuffEd() { diff --git a/src/app/ui/JuffMW.cpp b/src/app/ui/JuffMW.cpp index a34a0721..7b0984ba 100644 --- a/src/app/ui/JuffMW.cpp +++ b/src/app/ui/JuffMW.cpp @@ -382,6 +382,7 @@ void JuffMW::closeEvent(QCloseEvent* e) { bool confirmed = true; emit closeRequested(confirmed); + if ( confirmed ) { e->accept(); } @@ -390,27 +391,19 @@ void JuffMW::closeEvent(QCloseEvent* e) { } } -void JuffMW::resizeEvent(QResizeEvent* e) { -// LOGGER; - - QMainWindow::resizeEvent(e); - - if ( !isMaximized() ) { - MainSettings::setGeometry(geometry()); - } -} +//void JuffMW::resizeEvent(QResizeEvent* e) { +//// LOGGER; +// +// QMainWindow::resizeEvent(e); +//} -void JuffMW::changeEvent(QEvent* e) { - if ( e->type() == QEvent::WindowStateChange ) { - MainSettings::set(MainSettings::Maximized, isMaximized()); - } - QMainWindow::changeEvent(e); -} +//void JuffMW::changeEvent(QEvent* e) { +// QMainWindow::changeEvent(e); +//} -void JuffMW::moveEvent(QMoveEvent* e) { - MainSettings::setGeometry(geometry()); - QMainWindow::moveEvent(e); -} +//void JuffMW::moveEvent(QMoveEvent* e) { +// QMainWindow::moveEvent(e); +//} void JuffMW::keyPressEvent(QKeyEvent* e) { if ( searchPopup_->isVisible() ) { @@ -473,11 +466,20 @@ void JuffMW::applySettings() { void JuffMW::saveState() { MainSettings::setMwState(QMainWindow::saveState()); -// guiManager_.saveLastStates(); + MainSettings::saveGeometry(saveGeometry()); + MainSettings::set(MainSettings::Maximized, isMaximized()); + + // guiManager_.saveLastStates(); } void JuffMW::restoreState() { // restore the position of toolbars and docks QMainWindow::restoreState(MainSettings::mwState()); + + if ( MainSettings::get(MainSettings::Maximized) ) + showMaximized(); + else + QMainWindow::restoreGeometry(MainSettings::restoreGeometry()); + // guiManager_.loadLastStates(); } diff --git a/src/app/ui/JuffMW.h b/src/app/ui/JuffMW.h index 849779db..4361b4e4 100644 --- a/src/app/ui/JuffMW.h +++ b/src/app/ui/JuffMW.h @@ -90,11 +90,11 @@ protected slots: protected: virtual void closeEvent(QCloseEvent*); - virtual void resizeEvent(QResizeEvent*); - virtual void moveEvent(QMoveEvent*); + //virtual void resizeEvent(QResizeEvent*); + //virtual void moveEvent(QMoveEvent*); virtual void keyPressEvent(QKeyEvent*); virtual bool eventFilter(QObject*, QEvent*); - virtual void changeEvent(QEvent*); + //virtual void changeEvent(QEvent*); private: void updatePopupsPositions(); diff --git a/src/lib/MainSettings.cpp b/src/lib/MainSettings.cpp index 5fb857d7..d14f1ad2 100644 --- a/src/lib/MainSettings.cpp +++ b/src/lib/MainSettings.cpp @@ -206,12 +206,13 @@ QString MainSettings::get(StringKey key) { } } -void MainSettings::setGeometry(const QRect& rect) { - Settings::instance()->setValue("main", "geometry", rect); +void MainSettings::saveGeometry(const QByteArray& geo) { + Settings::instance()->setValue("main", "geometry", geo); } -QRect MainSettings::geometry() { - return Settings::instance()->value("main", "geometry", Settings::instance()->defaultValue("main", "geometry")).toRect(); +QByteArray MainSettings::restoreGeometry() { + //return Settings::instance()->value("main", "geometry", Settings::instance()->defaultValue("main", "geometry")); + return Settings::instance()->value("main", "geometry").toByteArray(); } void MainSettings::setMwState(const QByteArray& state) { diff --git a/src/lib/Settings.cpp b/src/lib/Settings.cpp index 2c303b30..4a3d2bd7 100644 --- a/src/lib/Settings.cpp +++ b/src/lib/Settings.cpp @@ -149,7 +149,7 @@ QVariant Settings::defaultValue(const QString& section, const QString& key) { if ( key.compare("iconTheme") == 0 ) return ""; if ( key.compare("lastOpenDir") == 0 ) return QDir::homePath(); if ( key.compare("lastSaveDir") == 0 ) return QDir::homePath(); - if ( key.compare("geometry") == 0 ) return QRect(50, 50, 800, 600); +// if ( key.compare("geometry") == 0 ) return QRect(50, 50, 800, 600); if ( key.compare("fsHideToolBar") == 0 ) return true; if ( key.compare("fsHideStatusBar") == 0 ) return true; if ( key.compare("language") == 0 ) return "auto"; From df8919cf5b3365e40f4bb51a04536310bb416c42 Mon Sep 17 00:00:00 2001 From: Petr Vanek Date: Tue, 15 Oct 2013 08:08:02 +0200 Subject: [PATCH 3/5] QDirModel replaced by much (and I mean really much) faster QFileSystemModel; fm plugin: fixed #57 Option to show hidden files --- plugins/findinfiles/SearchDlg.cpp | 14 +++++++-- plugins/findinfiles/SearchDlg.h | 5 ++-- plugins/fm/FMPlugin.cpp | 47 +++++++++++++++++++------------ plugins/fm/FMPlugin.h | 9 ++++-- plugins/fm/TreeView.cpp | 24 ++++++++-------- 5 files changed, 60 insertions(+), 39 deletions(-) diff --git a/plugins/findinfiles/SearchDlg.cpp b/plugins/findinfiles/SearchDlg.cpp index 60a72b66..f5efa183 100644 --- a/plugins/findinfiles/SearchDlg.cpp +++ b/plugins/findinfiles/SearchDlg.cpp @@ -4,12 +4,17 @@ #include #include +#include + SearchDlg::SearchDlg(QWidget* parent) : QDialog(parent) { ui.setupUi(this); - model_.setSorting(QDir::DirsFirst); - ui.dirEd->setCompleter(new QCompleter(&model_)); + QCompleter *completer = new QCompleter(this); + model = new QFileSystemModel(completer); + model->setRootPath(""); + completer->setModel(model); + ui.dirEd->setCompleter(completer); connect(ui.browseBtn, SIGNAL(clicked()), SLOT(slotBrowse())); @@ -19,8 +24,10 @@ SearchDlg::SearchDlg(QWidget* parent) : QDialog(parent) { void SearchDlg::slotBrowse() { QString dir = ui.dirEd->text(); dir = QFileDialog::getExistingDirectory(parentWidget(), tr("Browse"), dir); - if ( !dir.isEmpty() ) + if ( !dir.isEmpty() ) { ui.dirEd->setText(dir); + model->setRootPath(dir); + } } @@ -64,6 +71,7 @@ void SearchDlg::setFindText(const QString& text) { } void SearchDlg::setStartDir(const QString& dir) { ui.dirEd->setText(dir); + model->setRootPath(dir); } void SearchDlg::setSearchInFiles(bool inFiles) { if ( inFiles ) { diff --git a/plugins/findinfiles/SearchDlg.h b/plugins/findinfiles/SearchDlg.h index a8d4e710..44f54417 100644 --- a/plugins/findinfiles/SearchDlg.h +++ b/plugins/findinfiles/SearchDlg.h @@ -3,7 +3,8 @@ #include "ui_SearchDlg.h" -#include +class QFileSystemModel; + class SearchDlg : public QDialog { Q_OBJECT @@ -31,7 +32,7 @@ private slots: private: Ui::SearchDlg ui; - QDirModel model_; + QFileSystemModel *model; }; #endif /* __SEARCH_DLG_H__ */ diff --git a/plugins/fm/FMPlugin.cpp b/plugins/fm/FMPlugin.cpp index 3fdb08b9..6b90fb22 100644 --- a/plugins/fm/FMPlugin.cpp +++ b/plugins/fm/FMPlugin.cpp @@ -22,9 +22,8 @@ #include "TreeView.h" FMPlugin::FMPlugin() : QObject(), JuffPlugin() { - model_.setSorting(QDir::DirsFirst); - showAsTree = PluginSettings::getBool(this, "ShowAsTree", false); + showHidden = PluginSettings::getBool(this, "ShowHidden", false); w_ = new QWidget(); w_->setWindowTitle(tr("Files")); @@ -33,14 +32,15 @@ FMPlugin::FMPlugin() : QObject(), JuffPlugin() { //! \todo TODO/FIXME: maybe it could be configured with MainSettings::get(MainSettings::IconSize)... toolBar->setIconSize(QSize(16, 16)); + model_.setRootPath(""); + tree_ = new TreeView(this); tree_->setModel(&model_); tree_->setDragDropMode(QAbstractItemView::DragOnly); tree_->setAllColumnsShowFocus(true); + tree_->sortByColumn(-1, Qt::AscendingOrder); + tree_->setSortingEnabled(true); tree_->setSelectionMode(QAbstractItemView::ExtendedSelection); - // now configured by prefs - see showAsTree member - //tree_->setRootIsDecorated(false); - //tree_->setItemsExpandable(false); tree_->header()->resizeSection(0, 180); tree_->header()->resizeSection(1, 80); tree_->header()->resizeSection(2, 60); @@ -153,7 +153,6 @@ void FMPlugin::cd(const QString& path, bool addToHistory /*= true*/) { } tree_->setRootIndex(model_.index(path)); - model_.refresh(); pathEd_->setText(path); pathEd_->setToolTip(path); PluginSettings::set(this, "lastDir", path); @@ -174,7 +173,6 @@ void FMPlugin::itemDoubleClicked(const QModelIndex& index) { } void FMPlugin::onDirChanged(const QString&) { - model_.refresh(); } void FMPlugin::back() { @@ -220,16 +218,14 @@ void FMPlugin::favorites() { void FMPlugin::newDir() { QString newDirName = QInputDialog::getText(tree_, tr("New directory"), tr("Directory name")); - if ( !newDirName.isEmpty() ) { - QDir curDir(model_.filePath(tree_->rootIndex())); - if ( !curDir.mkdir(newDirName) ) { - QMessageBox::warning(tree_, tr("Warning"), - tr("Couldn't create a dir named '%1'").arg(newDirName)); - } - else { - model_.refresh(tree_->rootIndex()); - } - } + if (newDirName.isEmpty()) + return; + + QDir curDir(model_.filePath(tree_->rootIndex())); + if ( !curDir.mkdir(newDirName) ) { + QMessageBox::warning(tree_, tr("Warning"), + tr("Couldn't create a dir named '%1'").arg(newDirName)); + } } @@ -269,7 +265,7 @@ void FMPlugin::textEntered() { } void FMPlugin::onDocSaved(const QString& fileName) { - model_.refresh(model_.index(QFileInfo(fileName).absolutePath())); + Q_UNUSED(fileName); } void FMPlugin::applySettings() { @@ -284,6 +280,11 @@ void FMPlugin::applySettings() { PluginSettings::set(this, "ShowAsTree", showAsTree); tree_->setRootIsDecorated(showAsTree); tree_->setItemsExpandable(showAsTree); + + QDir::Filters filter = QDir::AllDirs | QDir::AllEntries | QDir::NoDotAndDotDot; + if (showHidden) + filter |= QDir::Hidden; + model_.setFilter(filter); } QWidget * FMPlugin::settingsPage() const @@ -296,7 +297,12 @@ QWidget * FMPlugin::settingsPage() const treeCheckBox->setChecked(showAsTree); connect(treeCheckBox, SIGNAL(toggled(bool)), this, SLOT(treeCheckBox_toggled(bool))); + QCheckBox *showHiddenBox = new QCheckBox(tr("Show Hidden Files and Directories"), cfg); + showHiddenBox->setChecked(showHidden); + connect(showHiddenBox, SIGNAL(toggled(bool)), this, SLOT(showHiddenBox_toggled(bool))); + l->addWidget(treeCheckBox); + l->addWidget(showHiddenBox); l->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding)); return cfg; } @@ -306,4 +312,9 @@ void FMPlugin::treeCheckBox_toggled(bool value) showAsTree = value; } +void FMPlugin::showHiddenBox_toggled(bool value) +{ + showHidden = value; +} + Q_EXPORT_PLUGIN2(fm, FMPlugin) diff --git a/plugins/fm/FMPlugin.h b/plugins/fm/FMPlugin.h index 14b3d0d6..132c7dd3 100644 --- a/plugins/fm/FMPlugin.h +++ b/plugins/fm/FMPlugin.h @@ -8,8 +8,7 @@ class TreeView; #include #include #include -#include -#include +#include #include @@ -48,6 +47,8 @@ protected slots: void manageFavorites(); void textEntered(); void treeCheckBox_toggled(bool value); + void showHiddenBox_toggled(bool value); + void onDirChanged(const QString&); private: @@ -55,9 +56,11 @@ protected slots: void initFavoritesMenu(); bool showAsTree; + bool showHidden; + QWidget* w_; TreeView* tree_; - QDirModel model_; + QFileSystemModel model_; QLineEdit* pathEd_; QAction* backBtn_; QStack history_; diff --git a/plugins/fm/TreeView.cpp b/plugins/fm/TreeView.cpp index e731576e..9fdf8550 100644 --- a/plugins/fm/TreeView.cpp +++ b/plugins/fm/TreeView.cpp @@ -2,12 +2,12 @@ #include "TreeView.h" -#include #include #include #include #include #include +#include #include @@ -66,22 +66,20 @@ void TreeView::keyPressEvent(QKeyEvent* e) { } void TreeView::renameCurrent() { - QDirModel* dirModel = qobject_cast(model()); + QFileSystemModel* dirModel = qobject_cast(model()); if ( 0 != dirModel ) { QFileInfo fi = dirModel->fileInfo(currentIndex()); QString newFileName = QInputDialog::getText(this, tr("Rename"), tr("File name"), QLineEdit::Normal, fi.fileName()); - if ( !newFileName.isEmpty() ) { - QFile file(fi.absoluteFilePath()); - QDir::setCurrent(fi.absolutePath()); - if ( !file.rename(newFileName) ) { - QMessageBox::warning(this, tr("Warning"), - tr("Rename failed: file '%1' already exists").arg(newFileName)); - } - else { - dirModel->refresh(dirModel->index(fi.absolutePath())); - } - } + if (newFileName.isEmpty()) + return; + + QFile file(fi.absoluteFilePath()); + QDir::setCurrent(fi.absolutePath()); + if ( !file.rename(newFileName) ) { + QMessageBox::warning(this, tr("Warning"), + tr("Rename failed: file '%1' already exists").arg(newFileName)); + } } } From d52e166b7eb32b0c376189acfcf117a0c71cf3dd Mon Sep 17 00:00:00 2001 From: Petr Vanek Date: Wed, 16 Oct 2013 15:00:55 +0200 Subject: [PATCH 4/5] fm: useless slot/icon removed --- plugins/fm/FMPlugin.cpp | 1 - plugins/fm/fm.qrc | 1 - 2 files changed, 2 deletions(-) diff --git a/plugins/fm/FMPlugin.cpp b/plugins/fm/FMPlugin.cpp index 6b90fb22..ee264d2c 100644 --- a/plugins/fm/FMPlugin.cpp +++ b/plugins/fm/FMPlugin.cpp @@ -52,7 +52,6 @@ FMPlugin::FMPlugin() : QObject(), JuffPlugin() { toolBar->addAction(QIcon(":icon_up"), tr("Go Up"), this, SLOT(up())); toolBar->addAction(QIcon(":icon_home"), tr("Go to Home Directory"), this, SLOT(home())); toolBar->addAction(QIcon(":icon_current"), tr("Go to current file's directory"), this, SLOT(curFileDir())); - toolBar->addAction(QIcon(":icon_refresh"), tr("Refresh List"), &model_, SLOT(refresh())); toolBar->addAction(QIcon(":icon_bookmarks"), tr("Favorite Locations"), this, SLOT(favorites())); toolBar->addAction(QIcon(":icon_new_dir"), tr("New Directory"), this, SLOT(newDir())); diff --git a/plugins/fm/fm.qrc b/plugins/fm/fm.qrc index a7eecd5a..4ebc4af8 100644 --- a/plugins/fm/fm.qrc +++ b/plugins/fm/fm.qrc @@ -4,7 +4,6 @@ go-up.png go-home.png go-current.png - view-refresh.png bookmark-new.png folder-new.png From 480bb6024f21551806841dd3df7fbc87152546a0 Mon Sep 17 00:00:00 2001 From: Petr Vanek Date: Wed, 16 Oct 2013 15:22:53 +0200 Subject: [PATCH 5/5] fm: saved file tree sorting --- plugins/fm/FMPlugin.cpp | 6 +++++- plugins/fm/FMPlugin.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/fm/FMPlugin.cpp b/plugins/fm/FMPlugin.cpp index ee264d2c..5c03e883 100644 --- a/plugins/fm/FMPlugin.cpp +++ b/plugins/fm/FMPlugin.cpp @@ -24,6 +24,7 @@ FMPlugin::FMPlugin() : QObject(), JuffPlugin() { showAsTree = PluginSettings::getBool(this, "ShowAsTree", false); showHidden = PluginSettings::getBool(this, "ShowHidden", false); + sortColumn = PluginSettings::getInt(this, "sortColumn", 0); w_ = new QWidget(); w_->setWindowTitle(tr("Files")); @@ -38,7 +39,7 @@ FMPlugin::FMPlugin() : QObject(), JuffPlugin() { tree_->setModel(&model_); tree_->setDragDropMode(QAbstractItemView::DragOnly); tree_->setAllColumnsShowFocus(true); - tree_->sortByColumn(-1, Qt::AscendingOrder); + tree_->sortByColumn(sortColumn, Qt::AscendingOrder); tree_->setSortingEnabled(true); tree_->setSelectionMode(QAbstractItemView::ExtendedSelection); tree_->header()->resizeSection(0, 180); @@ -93,6 +94,9 @@ FMPlugin::FMPlugin() : QObject(), JuffPlugin() { } FMPlugin::~FMPlugin() { + sortColumn = tree_->header()->sortIndicatorSection(); + PluginSettings::set(this, "sortColumn", sortColumn); + delete w_; } diff --git a/plugins/fm/FMPlugin.h b/plugins/fm/FMPlugin.h index 132c7dd3..5dd553ca 100644 --- a/plugins/fm/FMPlugin.h +++ b/plugins/fm/FMPlugin.h @@ -57,6 +57,7 @@ protected slots: bool showAsTree; bool showHidden; + int sortColumn; QWidget* w_; TreeView* tree_;