Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Mezomish/juffed
Browse files Browse the repository at this point in the history
  • Loading branch information
cessen committed Oct 27, 2013
2 parents 9912b80 + 480bb60 commit 92bff23
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 85 deletions.
29 changes: 20 additions & 9 deletions CMakeLists.txt
Expand Up @@ -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} )
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions include/MainSettings.h
Expand Up @@ -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);
};
Expand Down
14 changes: 11 additions & 3 deletions plugins/findinfiles/SearchDlg.cpp
Expand Up @@ -4,12 +4,17 @@

#include <QtGui/QCompleter>
#include <QtGui/QFileDialog>
#include <QFileSystemModel>


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()));

Expand All @@ -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);
}
}


Expand Down Expand Up @@ -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 ) {
Expand Down
5 changes: 3 additions & 2 deletions plugins/findinfiles/SearchDlg.h
Expand Up @@ -3,7 +3,8 @@

#include "ui_SearchDlg.h"

#include <QtGui/QDirModel>
class QFileSystemModel;


class SearchDlg : public QDialog {
Q_OBJECT
Expand Down Expand Up @@ -31,7 +32,7 @@ private slots:

private:
Ui::SearchDlg ui;
QDirModel model_;
QFileSystemModel *model;
};

#endif /* __SEARCH_DLG_H__ */
52 changes: 33 additions & 19 deletions plugins/fm/FMPlugin.cpp
Expand Up @@ -22,9 +22,9 @@
#include "TreeView.h"

FMPlugin::FMPlugin() : QObject(), JuffPlugin() {
model_.setSorting(QDir::DirsFirst);

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"));
Expand All @@ -33,14 +33,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(sortColumn, 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);
Expand All @@ -52,7 +53,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()));

Expand Down Expand Up @@ -94,6 +94,9 @@ FMPlugin::FMPlugin() : QObject(), JuffPlugin() {
}

FMPlugin::~FMPlugin() {
sortColumn = tree_->header()->sortIndicatorSection();
PluginSettings::set(this, "sortColumn", sortColumn);

delete w_;
}

Expand Down Expand Up @@ -153,7 +156,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);
Expand All @@ -174,7 +176,6 @@ void FMPlugin::itemDoubleClicked(const QModelIndex& index) {
}

void FMPlugin::onDirChanged(const QString&) {
model_.refresh();
}

void FMPlugin::back() {
Expand Down Expand Up @@ -220,16 +221,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));
}
}


Expand Down Expand Up @@ -269,7 +268,7 @@ void FMPlugin::textEntered() {
}

void FMPlugin::onDocSaved(const QString& fileName) {
model_.refresh(model_.index(QFileInfo(fileName).absolutePath()));
Q_UNUSED(fileName);
}

void FMPlugin::applySettings() {
Expand All @@ -284,6 +283,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
Expand All @@ -296,7 +300,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;
}
Expand All @@ -306,4 +315,9 @@ void FMPlugin::treeCheckBox_toggled(bool value)
showAsTree = value;
}

void FMPlugin::showHiddenBox_toggled(bool value)
{
showHidden = value;
}

Q_EXPORT_PLUGIN2(fm, FMPlugin)
10 changes: 7 additions & 3 deletions plugins/fm/FMPlugin.h
Expand Up @@ -8,8 +8,7 @@ class TreeView;
#include <QtCore>
#include <QtCore/QObject>
#include <QtCore/QStack>
#include <QtGui/QDirModel>
#include <QFileSystemWatcher>
#include <QFileSystemModel>

#include <JuffPlugin.h>

Expand Down Expand Up @@ -48,16 +47,21 @@ protected slots:
void manageFavorites();
void textEntered();
void treeCheckBox_toggled(bool value);
void showHiddenBox_toggled(bool value);

void onDirChanged(const QString&);

private:
void cd(const QString&, bool addToHistory = true);
void initFavoritesMenu();

bool showAsTree;
bool showHidden;
int sortColumn;

QWidget* w_;
TreeView* tree_;
QDirModel model_;
QFileSystemModel model_;
QLineEdit* pathEd_;
QAction* backBtn_;
QStack<QString> history_;
Expand Down
24 changes: 11 additions & 13 deletions plugins/fm/TreeView.cpp
Expand Up @@ -2,12 +2,12 @@

#include "TreeView.h"

#include <QDirModel>
#include <QInputDialog>
#include <QMessageBox>
#include <QtGui/QKeyEvent>
#include <QtGui/QHeaderView>
#include <QtGui/QMenu>
#include <QFileSystemModel>

#include <PluginSettings.h>

Expand Down Expand Up @@ -66,22 +66,20 @@ void TreeView::keyPressEvent(QKeyEvent* e) {
}

void TreeView::renameCurrent() {
QDirModel* dirModel = qobject_cast<QDirModel*>(model());
QFileSystemModel* dirModel = qobject_cast<QFileSystemModel*>(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));
}
}
}

Expand Down
1 change: 0 additions & 1 deletion plugins/fm/fm.qrc
Expand Up @@ -4,7 +4,6 @@
<file alias="icon_up">go-up.png</file>
<file alias="icon_home">go-home.png</file>
<file alias="icon_current">go-current.png</file>
<file alias="icon_refresh">view-refresh.png</file>
<file alias="icon_bookmarks">bookmark-new.png</file>
<file alias="icon_new_dir">folder-new.png</file>
</qresource>
Expand Down
6 changes: 1 addition & 5 deletions src/app/JuffEd.cpp
Expand Up @@ -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() {
Expand Down

0 comments on commit 92bff23

Please sign in to comment.