* respect the --select startup option

* minor cleanups related to selecting items in general

svn path=/trunk/KDE/kdebase/apps/; revision=1063329
This commit is contained in:
Peter Penz 2009-12-17 21:07:18 +00:00
parent d613313b06
commit e15a9f3a8d
9 changed files with 131 additions and 99 deletions

View file

@ -72,57 +72,36 @@ void DolphinApplication::refreshMainWindows()
int DolphinApplication::newInstance()
{
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
static bool first = true;
switch (args->count()) {
case 0:
if( !first || !isSessionRestored()) {
openWindow(KUrl());
}
break;
case 1:
openWindow(args->url(0));
break;
case 2:
openSplitWindow(args->url(0),args->url(1));
break;
default:
for (int i = 0; i < args->count(); ++i) {
openWindow(args->url(i));
}
QList<KUrl> urls;
const int argsCount = args->count();
for (int i = 0; i < argsCount; ++i) {
urls.append(args->url(i));
}
first = false;
DolphinMainWindow* win = createMainWindow();
if (urls.count() > 0) {
if (args->isSet("select")) {
win->openFiles(urls);
} else {
win->openDirectories(urls);
}
}
win->show();
args->clear();
return 0;
}
int DolphinApplication::openWindow(const KUrl& url)
int DolphinApplication::openWindow(const QString& urlString)
{
DolphinMainWindow* win = createMainWindow();
if ((win->activeViewContainer() != 0) && url.isValid()) {
win->activeViewContainer()->setUrl(url);
const KUrl url(urlString);
if (!url.isEmpty()) {
win->openDirectories(QList<KUrl>() << url);
}
win->show();
return win->getId();
}
int DolphinApplication::openSplitWindow(const KUrl& leftUrl, const KUrl& rightUrl)
{
DolphinMainWindow* win = createMainWindow();
if ((win->activeViewContainer() != 0) && leftUrl.isValid()) {
win->activeViewContainer()->setUrl(leftUrl);
}
win->toggleSplitView();
if ((win->activeViewContainer() != 0) && rightUrl.isValid()){
win->activeViewContainer()->setUrl(rightUrl);
}
win->show();
return win->getId();
}
#include "dolphinapplication.moc"

View file

@ -23,7 +23,6 @@
#define _DOLPHIN_APPLICATION_H
#include <kuniqueapplication.h>
#include <kurl.h>
class DolphinMainWindow;
class KUrl;
@ -56,11 +55,10 @@ public:
/** @see KUniqueApplication::newInstance(). */
virtual int newInstance();
public slots:
int openWindow(const KUrl& url);
int openSplitWindow(const KUrl& leftUrl,const KUrl& rightUrl);
/** Interface implementation for D-Bus Interface. */
int openWindow(const QString& urlString);
protected:
private:
/** Called by the DolphinMainWindow to deregister. */
void removeMainWindow(DolphinMainWindow* mainWindow);

View file

@ -151,6 +151,64 @@ DolphinMainWindow::~DolphinMainWindow()
DolphinApplication::app()->removeMainWindow(this);
}
void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
{
if (dirs.isEmpty()) {
return;
}
const int oldOpenTabsCount = m_viewTab.count();
const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
const bool hasSplitView = generalSettings->splitView();
// Open each directory inside a new tab. If the "split view" option has been enabled,
// always show two directories within one tab.
QList<KUrl>::const_iterator it = dirs.begin();
while (it != dirs.end()) {
openNewTab(*it);
++it;
if (hasSplitView && (it != dirs.end())) {
const int tabIndex = m_viewTab.count() - 1;
m_viewTab[tabIndex].secondaryView->setUrl(*it);
++it;
}
}
// remove the previously opened tabs
for (int i = 0; i < oldOpenTabsCount; ++i) {
closeTab(0);
}
}
void DolphinMainWindow::openFiles(const QList<KUrl>& files)
{
// Get all distinct directories from 'files' and open a tab
// for each directory. If the "split view" option is enabled, two
// directories are shown inside one tab (see openDirectories()).
QList<KUrl> dirs;
foreach (const KUrl& url, files) {
const KUrl dir(url.directory());
if (!dirs.contains(dir)) {
dirs.append(dir);
}
}
openDirectories(dirs);
// Select the files. Although the files can be split between several
// tabs, there is no need to split 'files' accordingly, as
// the DolphinView will just ignore invalid selections.
const int tabCount = m_viewTab.count();
for (int i = 0; i < tabCount; ++i) {
m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
if (m_viewTab[i].secondaryView != 0) {
m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
}
}
}
void DolphinMainWindow::toggleViews()
{
if (m_viewTab[m_tabIndex].primaryView == 0) {
@ -251,11 +309,6 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
}
}
void DolphinMainWindow::changeSelection(const KFileItemList& selection)
{
activeViewContainer()->view()->changeSelection(selection);
}
void DolphinMainWindow::slotEditableStateChanged(bool editable)
{
KToggleAction* editableLocationAction =
@ -1406,8 +1459,6 @@ void DolphinMainWindow::setupDockWidgets()
foldersPanel, SLOT(setUrl(KUrl)));
connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)),
this, SLOT(changeSelection(KFileItemList)));
// setup "Terminal"
#ifndef Q_OS_WIN

View file

@ -73,6 +73,19 @@ public:
*/
DolphinViewContainer* activeViewContainer() const;
/**
* Opens each directory \p in a separate tab. If the "split view"
* option is enabled, 2 directories are collected within one tab.
*/
void openDirectories(const QList<KUrl>& dirs);
/**
* Opens the directory which contains the files \p files
* and selects all files (implements the --select option
* of Dolphin).
*/
void openFiles(const QList<KUrl>& files);
/**
* Returns true, if the main window contains two instances
* of a view container. The active view constainer can be
@ -123,17 +136,12 @@ public slots:
int getId() const;
/**
* Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
* Inform all affected dolphin components (panels, views) of an URL
* change.
*/
void changeUrl(const KUrl& url);
/**
* Inform all affected dolphin components that a selection change is
* requested.
*/
void changeSelection(const KFileItemList& selection);
/** Stores all settings and quits Dolphin. */
void quit();

View file

@ -291,6 +291,14 @@ bool DolphinView::hasSelection() const
return view && view->selectionModel()->hasSelection();
}
void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
{
foreach (const KUrl& url, urls) {
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
m_selectedItems.append(item);
}
}
KFileItemList DolphinView::selectedItems() const
{
const QAbstractItemView* view = m_viewAccessor.itemView();
@ -441,7 +449,7 @@ void DolphinView::reload()
QByteArray viewState;
QDataStream saveStream(&viewState, QIODevice::WriteOnly);
saveState(saveStream);
m_selectedItems = selectedItems();
m_selectedItems= selectedItems();
setUrl(url());
loadDirectory(url(), true);
@ -598,27 +606,6 @@ void DolphinView::clearSelection()
m_viewAccessor.itemView()->clearSelection();
}
void DolphinView::changeSelection(const KFileItemList& selection)
{
clearSelection();
if (selection.isEmpty()) {
return;
}
const KUrl& baseUrl = url();
KUrl url;
QItemSelection newSelection;
foreach(const KFileItem& item, selection) {
url = item.url().upUrl();
if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
newSelection.select(index, index);
}
}
m_viewAccessor.itemView()->selectionModel()->select(newSelection,
QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Current);
}
void DolphinView::renameSelectedItems()
{
KFileItemList items = selectedItems();
@ -1227,7 +1214,19 @@ void DolphinView::slotLoadingCompleted()
}
if (!m_selectedItems.isEmpty()) {
changeSelection(m_selectedItems);
const KUrl& baseUrl = url();
KUrl url;
QItemSelection newSelection;
foreach(const KFileItem& item, m_selectedItems) {
url = item.url().upUrl();
if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
newSelection.select(index, index);
}
}
m_viewAccessor.itemView()->selectionModel()->select(newSelection,
QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Current);
m_selectedItems.clear();
}

View file

@ -179,6 +179,14 @@ public:
*/
bool supportsCategorizedSorting() const;
/**
* Marks the items indicated by \p urls to get selected after the
* directory DolphinView::url() has been loaded. Note that nothing
* gets selected if no loading of a directory has been triggered
* by DolphinView::setUrl() or DolphinView::reload().
*/
void markUrlsAsSelected(const QList<KUrl>& urls);
/**
* Returns the selected items. The list is empty if no item has been
* selected.
@ -381,14 +389,6 @@ public slots:
void clearSelection();
/**
* Request of a selection change. The view will do its best to accommodate
* the request, but it is not guaranteed that all items in \a selection
* will actually get selected. The view will e.g. not select items which
* are not in the currently displayed folder.
*/
void changeSelection(const KFileItemList& selection);
/**
* Triggers the renaming of the currently selected items, where
* the user must input a new name for the items.

View file

@ -68,7 +68,14 @@ int main(int argc, char **argv)
KCmdLineArgs::init(argc, argv, &about);
KCmdLineOptions options;
options.add("+[Url]", ki18nc("@info:shell", "Document to open"));
// TODO KDE SC 4.5: The string freeze is valid and no new localized strings are allowed.
// To get in the --select option that was available in Konqueror 3, an already existing
// string ("Document to open") is used as workaround (the --select option will most probably
// anyhow used by applications and not by users).
const KLocalizedString& documentToOpen = ki18nc("@info:shell", "Document to open");
options.add("select", documentToOpen);
options.add("+[Url]", documentToOpen);
KCmdLineArgs::addCmdLineOptions(options);
if (!DolphinApplication::start()) {

View file

@ -185,7 +185,6 @@ void FoldersPanel::contextMenuEvent(QContextMenuEvent* event)
if (index.isValid()) {
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
emit changeSelection(KFileItemList());
}
TreeViewContextMenu contextMenu(this, item);

View file

@ -59,15 +59,6 @@ signals:
*/
void changeUrl(const KUrl& url, Qt::MouseButtons buttons);
/**
* This signal is emitted when the panel requests a change in the
* current selection. The file-management view recieving this signal is
* not required to select all listed files, limiting the selection to
* e.g. the current folder. The new selection will be reported via the
* setSelection slot.
*/
void changeSelection(const KFileItemList& selection);
public slots:
/**
* Changes the current selection inside the tree to \a url.