Commit a2e8492f authored by Peter Penz's avatar Peter Penz
Browse files

Cleanup of signal/slot handling between the dolphin view and the main window:...

Cleanup of signal/slot handling between the dolphin view and the main window: now the main window listens to the signals from the dolphin view and connects to private slots (previously the dolphin view connected to public slots of the main window). Also prevent naming all slots by the prefix 'slot', describe instead what the method does.

svn path=/trunk/playground/utils/dolphin/; revision=611617
parent 746e4e3e
......@@ -28,13 +28,28 @@ DolphinIconsView::DolphinIconsView(DolphinView* parent) :
QListView(parent),
m_parentView( parent )
{
setResizeMode( QListView::Adjust );
setResizeMode(QListView::Adjust);
}
DolphinIconsView::~DolphinIconsView()
{
}
QStyleOptionViewItem DolphinIconsView::viewOptions() const
{
return QListView::viewOptions();
// TODO: the view options should been read from the settings;
// the following code is just for testing...
//QStyleOptionViewItem options = QListView::viewOptions();
//options.decorationAlignment = Qt::AlignRight;
//options.decorationPosition = QStyleOptionViewItem::Right;
//options.decorationSize = QSize(100, 100);
//options.showDecorationSelected = true;
//options.state = QStyle::State_MouseOver;
//return options;
}
void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
{
QListView::contextMenuEvent(event);
......
......@@ -42,6 +42,7 @@ public:
virtual ~DolphinIconsView();
protected:
virtual QStyleOptionViewItem viewOptions() const;
virtual void contextMenuEvent(QContextMenuEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
......
......@@ -218,6 +218,7 @@ void DolphinMainWindow::refreshViews()
url,
props.viewMode(),
props.isShowHiddenFilesEnabled());
connectViewSignals(i);
m_view[i]->show();
}
}
......@@ -229,24 +230,6 @@ void DolphinMainWindow::refreshViews()
emit activeViewChanged();
}
void DolphinMainWindow::slotHistoryChanged()
{
updateHistory();
}
void DolphinMainWindow::slotUrlChanged(const KUrl& url)
{
updateEditActions();
updateGoActions();
setCaption(url.fileName());
}
void DolphinMainWindow::slotUrlChangeRequest(const KUrl& url)
{
clearStatusBar();
m_activeView->setUrl(url);
}
void DolphinMainWindow::slotViewModeChanged()
{
updateViewActions();
......@@ -259,13 +242,6 @@ void DolphinMainWindow::slotShowHiddenFilesChanged()
showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled());
}
void DolphinMainWindow::slotShowFilterBarChanged()
{
KToggleAction* showFilterBarAction =
static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
}
void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
{
QAction* action = 0;
......@@ -314,17 +290,36 @@ void DolphinMainWindow::slotSelectionChanged()
emit selectionChanged();
}
void DolphinMainWindow::slotRedo()
void DolphinMainWindow::slotHistoryChanged()
{
updateHistory();
}
void DolphinMainWindow::slotUrlChanged(const KUrl& url)
{
updateEditActions();
updateGoActions();
setCaption(url.fileName());
}
void DolphinMainWindow::updateFilterBarAction(bool show)
{
KToggleAction* showFilterBarAction =
static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
showFilterBarAction->setChecked(show);
}
void DolphinMainWindow::redo()
{
UndoManager::instance().redo(this);
}
void DolphinMainWindow::slotUndo()
void DolphinMainWindow::undo()
{
UndoManager::instance().undo(this);
}
void DolphinMainWindow::slotNewMainWindow()
void DolphinMainWindow::openNewMainWindow()
{
DolphinApplication::app()->createMainWindow()->show();
}
......@@ -826,6 +821,7 @@ void DolphinMainWindow::toggleSplitView()
m_view[PrimaryIdx]->url(),
m_view[PrimaryIdx]->mode(),
m_view[PrimaryIdx]->isShowHiddenFilesEnabled());
connectViewSignals(SecondaryIdx);
m_splitter->addWidget(m_view[SecondaryIdx]);
m_splitter->setSizes(QList<int>() << newWidth << newWidth);
m_view[SecondaryIdx]->show();
......@@ -1125,6 +1121,7 @@ void DolphinMainWindow::init()
homeUrl,
props.viewMode(),
props.isShowHiddenFilesEnabled());
connectViewSignals(PrimaryIdx);
m_view[PrimaryIdx]->show();
m_activeView = m_view[PrimaryIdx];
......@@ -1171,7 +1168,7 @@ void DolphinMainWindow::setupActions()
{
// setup 'File' menu
KAction *action = new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" );
connect(action, SIGNAL(triggered()), this, SLOT(slotNewMainWindow()));
connect(action, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder");
createFolder->setIcon(KIcon("folder"));
......@@ -1201,7 +1198,7 @@ void DolphinMainWindow::setupActions()
// setup 'Edit' menu
UndoManager& undoManager = UndoManager::instance();
KStdAction::undo(this,
SLOT(slotUndo()),
SLOT(undo()),
actionCollection());
connect(&undoManager, SIGNAL(undoAvailable(bool)),
this, SLOT(slotUndoAvailable(bool)));
......@@ -1209,7 +1206,7 @@ void DolphinMainWindow::setupActions()
this, SLOT(slotUndoTextChanged(const QString&)));
KStdAction::redo(this,
SLOT(slotRedo()),
SLOT(redo()),
actionCollection());
connect(&undoManager, SIGNAL(redoAvailable(bool)),
this, SLOT(slotRedoAvailable(bool)));
......@@ -1333,6 +1330,31 @@ void DolphinMainWindow::setupActions()
KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
}
void DolphinMainWindow::setupDockWidgets()
{
QDockWidget *shortcutsDock = new QDockWidget(i18n("Shortcuts"));
shortcutsDock->setObjectName("shortcutsDock");
shortcutsDock->setWidget(new BookmarksSidebarPage(this));
shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_pane");
shortcutsDock->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
actionCollection()->insert(shortcutsDock->toggleViewAction());
addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
QDockWidget *infoDock = new QDockWidget(i18n("Information"));
infoDock->setObjectName("infoDock");
infoDock->setWidget(new InfoSidebarPage(this));
infoDock->toggleViewAction()->setObjectName("show_info_pane");
infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
actionCollection()->insert(infoDock->toggleViewAction());
addDockWidget(Qt::RightDockWidgetArea, infoDock);
}
void DolphinMainWindow::setupCreateNewMenuActions()
{
// Parts of the following code have been taken
......@@ -1594,29 +1616,28 @@ void DolphinMainWindow::clearStatusBar()
m_activeView->statusBar()->clear();
}
void DolphinMainWindow::setupDockWidgets()
{
QDockWidget *shortcutsDock = new QDockWidget(i18n("Shortcuts"));
shortcutsDock->setObjectName("shortcutsDock");
shortcutsDock->setWidget(new BookmarksSidebarPage(this));
shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_pane");
shortcutsDock->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
actionCollection()->insert(shortcutsDock->toggleViewAction());
addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
void DolphinMainWindow::connectViewSignals(int viewIndex)
{
DolphinView* view = m_view[viewIndex];
connect(view, SIGNAL(modeChanged()),
this, SLOT(slotViewModeChanged()));
connect(view, SIGNAL(showHiddenFilesChanged()),
this, SLOT(slotShowHiddenFilesChanged()));
connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(slotSortingChanged(DolphinView::Sorting)));
connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
connect(view, SIGNAL(selectionChanged()),
this, SLOT(slotSelectionChanged()));
connect(view, SIGNAL(showFilterBarChanged(bool)),
this, SLOT(updateFilterBarAction(bool)));
const UrlNavigator* navigator = view->urlNavigator();
connect(navigator, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(slotUrlChanged(const KUrl&)));
connect(navigator, SIGNAL(historyChanged()),
this, SLOT(slotHistoryChanged()));
QDockWidget *infoDock = new QDockWidget(i18n("Information"));
infoDock->setObjectName("infoDock");
infoDock->setWidget(new InfoSidebarPage(this));
infoDock->toggleViewAction()->setObjectName("show_info_pane");
infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
actionCollection()->insert(infoDock->toggleViewAction());
addDockWidget(Qt::RightDockWidgetArea, infoDock);
}
#include "dolphinmainwindow.moc"
......@@ -28,13 +28,14 @@
#include <kapplication.h>
#include <kmainwindow.h>
#include <ksortablelist.h>
#include <kvbox.h>
#include <q3valuelist.h>
#include <q3ptrlist.h>
#include <qstring.h>
//Added by qt3to4:
#include <QCloseEvent>
#include <ksortablelist.h>
#include <kvbox.h>
#include <QString>
#include "dolphinview.h"
#include "undomanager.h"
......@@ -126,51 +127,6 @@ signals:
*/
void selectionChanged();
public slots:
/**
* Updates the state of the 'Back' and 'Forward' menu
* actions corresponding the the current history.
*/
void slotHistoryChanged();
/**
* Updates the caption of the main window and the state
* of all menu actions which depend from a changed Url.
*/
void slotUrlChanged(const KUrl& url);
/**
* Go to the given Url.
*/
void slotUrlChangeRequest(const KUrl& url);
/** Updates the state of all 'View' menu actions. */
void slotViewModeChanged();
/** Updates the state of the 'Show hidden files' menu action. */
void slotShowHiddenFilesChanged();
/** Updates the state of the 'Show filter bar' menu action. */
void slotShowFilterBarChanged();
/** Updates the state of the 'Sort by' actions. */
void slotSortingChanged(DolphinView::Sorting sorting);
/** Updates the state of the 'Sort Ascending/Descending' action. */
void slotSortOrderChanged(Qt::SortOrder order);
/** Updates the state of the 'Edit' menu actions. */
void slotSelectionChanged();
/** Executes Redo operation */
void slotRedo();
/** @see slotUndo() */
void slotUndo();
/** Open a new mainwindow */
void slotNewMainWindow();
protected:
/** @see QMainWindow::closeEvent */
virtual void closeEvent(QCloseEvent* event);
......@@ -371,6 +327,44 @@ private slots:
*/
void addUndoOperation(KJob* job);
/** Updates the state of all 'View' menu actions. */
void slotViewModeChanged();
/** Updates the state of the 'Show hidden files' menu action. */
void slotShowHiddenFilesChanged();
/** Updates the state of the 'Sort by' actions. */
void slotSortingChanged(DolphinView::Sorting sorting);
/** Updates the state of the 'Sort Ascending/Descending' action. */
void slotSortOrderChanged(Qt::SortOrder order);
/** Updates the state of the 'Edit' menu actions. */
void slotSelectionChanged();
/**
* Updates the state of the 'Back' and 'Forward' menu
* actions corresponding the the current history.
*/
void slotHistoryChanged();
/**
* Updates the caption of the main window and the state
* of all menu actions which depend from a changed Url.
*/
void slotUrlChanged(const KUrl& url);
/** Updates the state of the 'Show filter bar' menu action. */
void updateFilterBarAction(bool show);
/** Executes the redo operation (see UndoManager::Redo ()). */
void redo();
/** Executes the undo operation (see UndoManager::Undo()). */
void undo();
/** Open a new main window. */
void openNewMainWindow();
private:
DolphinMainWindow();
......@@ -394,6 +388,15 @@ private:
const KUrl& dest);
void clearStatusBar();
/**
* Connects the signals from the created DolphinView with
* the index \a viewIndex with the corresponding slots of
* the DolphinMainWindow. This method must be invoked each
* time a DolphinView has been created.
*/
void connectViewSignals(int viewIndex);
private:
QSplitter* m_splitter;
DolphinView* m_activeView;
......
......@@ -21,15 +21,13 @@
#include "dolphinview.h"
#include <QItemSelectionModel>
#include <kdirmodel.h>
#include <qlayout.h>
//Added by qt3to4:
#include <Q3ValueList>
#include <QDropEvent>
#include <QMouseEvent>
#include <QVBoxLayout>
#include <kdirmodel.h>
#include <kfileitemdelegate.h>
#include <kurl.h>
#include <klocale.h>
#include <kio/netaccess.h>
......@@ -48,7 +46,6 @@
#include "undomanager.h"
#include "renamedialog.h"
#include "progressindicator.h"
#include "filterbar.h"
DolphinView::DolphinView(DolphinMainWindow *mainWindow,
......@@ -57,10 +54,10 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
Mode mode,
bool showHiddenFiles) :
QWidget(parent),
m_mainWindow(mainWindow),
m_refreshing(false),
m_showProgress(false),
m_mode(mode),
m_mainWindow(mainWindow),
m_statusBar(0),
m_iconSize(0),
m_folderCount(0),
......@@ -73,22 +70,9 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
m_topLayout->setSpacing(0);
m_topLayout->setMargin(0);
connect(this, SIGNAL(signalModeChanged()),
mainWindow, SLOT(slotViewModeChanged()));
connect(this, SIGNAL(signalShowHiddenFilesChanged()),
mainWindow, SLOT(slotShowHiddenFilesChanged()));
connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting)),
mainWindow, SLOT(slotSortingChanged(DolphinView::Sorting)));
connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder)),
mainWindow, SLOT(slotSortOrderChanged(Qt::SortOrder)));
m_urlNavigator = new UrlNavigator(url, this);
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(slotUrlChanged(const KUrl&)));
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
mainWindow, SLOT(slotUrlChanged(const KUrl&)));
connect(m_urlNavigator, SIGNAL(historyChanged()),
mainWindow, SLOT(slotHistoryChanged()));
this, SLOT(loadDirectory(const KUrl&)));
m_statusBar = new DolphinStatusBar(this);
......@@ -110,29 +94,37 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
this, SLOT(slotErrorMessage(const QString&)));
m_iconsView = new DolphinIconsView(this);
connect(m_iconsView, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
applyModeToView();
KDirModel* model = new KDirModel();
model->setDirLister(m_dirLister);
m_iconsView->setModel(model);
KFileItemDelegate* delegate = new KFileItemDelegate(this);
m_iconsView->setItemDelegate(delegate);
m_dirLister->setDelayedMimeTypes(true);
new KMimeTypeResolver( m_iconsView, model );
new KMimeTypeResolver(m_iconsView, model);
m_iconSize = K3Icon::SizeMedium;
m_filterBar = new FilterBar(mainWindow, this);
m_filterBar = new FilterBar(this);
m_filterBar->hide();
connect(m_filterBar, SIGNAL(signalFilterChanged(const QString&)),
connect(m_filterBar, SIGNAL(filterChanged(const QString&)),
this, SLOT(slotChangeNameFilter(const QString&)));
connect(m_filterBar, SIGNAL(closed()),
this, SLOT(closeFilterBar()));
m_topLayout->addWidget(m_urlNavigator);
m_topLayout->addWidget(m_iconsView);
m_topLayout->addWidget(m_filterBar);
m_topLayout->addWidget(m_statusBar);
connect(m_iconsView, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
connect(m_iconsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(emitSelectionChangedSignal()));
startDirLister(m_urlNavigator->url());
}
......@@ -176,7 +168,7 @@ void DolphinView::setMode(Mode mode)
applyModeToView();
startDirLister(m_urlNavigator->url());
emit signalModeChanged();
emit modeChanged();
}
DolphinView::Mode DolphinView::mode() const
......@@ -196,7 +188,7 @@ void DolphinView::setShowHiddenFilesEnabled(bool show)
m_dirLister->setShowingDotFiles(show);
emit signalShowHiddenFilesChanged();
emit showHiddenFilesChanged();
reload();
}
......@@ -362,9 +354,14 @@ void DolphinView::updateStatusBar()
}
}
void DolphinView::requestItemInfo(const KUrl& url)
void DolphinView::emitRequestItemInfo(const KUrl& url)
{
emit requestItemInfo(url);
}
bool DolphinView::isFilterBarVisible() const
{
emit signalRequestItemInfo(url);
return m_filterBar->isVisible();
}
bool DolphinView::isUrlEditable() const
......@@ -633,7 +630,7 @@ DolphinMainWindow* DolphinView::mainWindow() const
return m_mainWindow;
}
void DolphinView::slotUrlChanged(const KUrl& url)
void DolphinView::loadDirectory(const KUrl& url)
{
const ViewProperties props(url);
setMode(props.viewMode());
......@@ -646,14 +643,7 @@ void DolphinView::slotUrlChanged(const KUrl& url)
setSortOrder(props.sortOrder());
startDirLister(url);
// The selectionChanged signal is not emitted when a new view object is
// created. The application does not care whether a view is represented by a
// different instance, hence inform the application that the selection might have
// changed so that it can update it's actions.
mainWindow()->slotSelectionChanged();
emit signalUrlChanged(url);
emit urlChanged(url);
}
void DolphinView::triggerIconsViewItem(Q3IconViewItem* item)
......@@ -821,6 +811,17 @@ void DolphinView::slotGrabActivation()
mainWindow()->setActiveView(this);
}
void DolphinView::emitSelectionChangedSignal()
{
emit selectionChanged();
}
void DolphinView::closeFilterBar()
{
m_filterBar->hide();
emit showFilterBarChanged(false);
}
void DolphinView::slotContentsMoving(int x, int y)
{
if (!m_refreshing) {
......@@ -1029,13 +1030,11 @@ void DolphinView::slotChangeNameFilter(const QString& nameFilter)
}*/
}
bool DolphinView::isFilterBarVisible()
{
return m_filterBar->isVisible();
}
void DolphinView::applyModeToView()
{
//m_iconsView->setAlternatingRowColors(true);
m_iconsView->setSelectionMode(QAbstractItemView::ExtendedSelection);
// TODO: the following code just tries to test some QListView capabilities
switch (m_mode) {
case IconsView:
......
......@@ -313,19 +313,14 @@ public:
/**
* Triggers to request user information for the item given
* by the Url \a url. The signal signalRequestItemInfo is emitted,
* by the Url \a url. The signal requestItemInfo is emitted,
* which provides a way for widgets to get an indication to update
* the item information.
*/
void requestItemInfo(const KUrl& url);
void emitRequestItemInfo(const KUrl& url);
/**
* Checks if the filter bar is visible.
*
* @return @c true Filter bar is visible.
* @return @c false Filter bar is not visible.
*/
bool isFilterBarVisible();
/** Returns true, if the filter bar is visible. */
bool isFilterBarVisible() const;
/**
* Return the DolphinMainWindow this View belongs to. It is guranteed
......@@ -351,28 +346,28 @@ public slots:
signals:
/** Is emitted if Url of the view has been changed to \a url. */
void signalUrlChanged(const KUrl& url);
void urlChanged(const KUrl& url);
/**
* Is emitted if the view mode (IconsView, DetailsView,
* PreviewsView) has been changed.
*/
void signalModeChanged();
void modeChanged();
/** Is emitted if the 'show hidden files' property has been changed. */
void signalShowHiddenFilesChanged();
void showHiddenFilesChanged();
/** Is emitted if the sorting by name, size or date has been changed. */
void signalSortingChanged(DolphinView::Sorting sorting);
void sortingChanged(DolphinView::Sorting sorting);
/** Is emitted if the sort order (ascending or descending) has been changed. */
void signalSortOrderChanged(Qt::SortOrder order);
void sortOrderChanged(Qt::SortOrder order);
/**