# # # add_file "src/view/WorkspaceWindow.cpp" # content [9453c2f9657078017bfa06650a50c5f2c980a9f1] # # add_file "src/view/WorkspaceWindow.h" # content [9f25aaa1b7dabd9f27b282231971212351c12b28] # ============================================================ --- src/view/WorkspaceWindow.cpp 9453c2f9657078017bfa06650a50c5f2c980a9f1 +++ src/view/WorkspaceWindow.cpp 9453c2f9657078017bfa06650a50c5f2c980a9f1 @@ -0,0 +1,299 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "WorkspaceWindow.h" +#include "Settings.h" +#include "Platform.h" +#include "Guitone.h" +#include "MonotoneUtil.h" +#include "InventoryItem.h" + +#include "WorkspaceMenuBar.h" +#include "WorkspaceDialogManager.h" + +WorkspaceWindow::WorkspaceWindow() : DatabaseWindow() {} + +WorkspaceWindow::~WorkspaceWindow() {} + +void WorkspaceWindow::init() +{ + cleanup(); + menuBar = new WorkspaceMenuBar(this); + dialogManager = new WorkspaceDialogManager(this); + + connect( + menuBar, SIGNAL(showUpdateWorkspace()), + dialogManager, SLOT(showUpdateWorkspace()) + ); + + connect( + menuBar, SIGNAL(showCommitRevision()), + dialogManager, SLOT(showCommitRevision()) + ); + + connect( + menuBar, SIGNAL(showUnaccountedRenames()), + this, SLOT(checkForUnaccountedRenames()) + ); + + // layout stuff + layout = new QHBoxLayout(this); + layout->setSpacing(0); + layout->setContentsMargins(0, 0, 0, 0); + + mainSplitter = new Splitter(this); + mainSplitter->setOrientation(Qt::Horizontal); + + treeView = new InventoryView(mainSplitter); + treeView->setType(InventoryView::FolderTree); + treeView->setEditTriggers(QAbstractItemView::EditKeyPressed); + treeView->setSelectionMode(QAbstractItemView::ExtendedSelection); + + listSplitter = new Splitter(mainSplitter); + listSplitter->setOrientation(Qt::Vertical); + + listView = new InventoryView(listSplitter); + listView->setType(InventoryView::FileList); + listView->setEditTriggers(QAbstractItemView::EditKeyPressed); + listView->setSelectionMode(QAbstractItemView::ExtendedSelection); + + attrView = new AttributesView(listSplitter); + attrView->setAlternatingRowColors(true); + + connect( + treeView, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(readAttributes(const QModelIndex &)) + ); + connect( + listView, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(readAttributes(const QModelIndex &)) + ); + + connect( + treeView, SIGNAL(directoryChanged(const QModelIndex &)), + listView, SLOT(changeDirectory(const QModelIndex &)) + ); + connect( + listView, SIGNAL(directoryChanged(const QModelIndex &)), + treeView, SLOT(changeDirectory(const QModelIndex &)) + ); + + connect( + listView, SIGNAL(diffFile(const QString &)), + dialogManager, SLOT(showFileDiff(const QString &)) + ); + + connect( + listView, SIGNAL(diffRevision(const QString &, const QString &, const QString &)), + dialogManager, SLOT(showRevisionDiff(const QString &, const QString &, const QString &)) + ); + + connect( + listView, SIGNAL(fileHistory(const QString &)), + dialogManager, SLOT(showFileHistory(const QString &)) + ); + + connect( + listView, SIGNAL(openFile(const QString &)), + this, SLOT(openFile(const QString &)) + ); + + // the tree view shows only directories, therefor file diff / file history + // doesn't make sense there + connect( + treeView, SIGNAL(diffRevision(const QString &, const QString &, const QString &)), + dialogManager, SLOT(showRevisionDiff(const QString &, const QString &, const QString &)) + ); + + connect( + treeView, SIGNAL(openFile(const QString &)), + this, SLOT(openFile(const QString &)) + ); + + connect( + menuBar, SIGNAL(expandTree(bool)), + treeView, SLOT(setExpanded(bool)) + ); + + listSplitter->addWidget(listView); + listSplitter->addWidget(attrView); + + mainSplitter->addWidget(treeView); + mainSplitter->addWidget(listSplitter); + + layout->addWidget(mainSplitter); + setLayout(layout); + + mainSplitter->init(); + listSplitter->init(); + + // models + invModel = new Inventory(this, workspacePath); + attrModel = new GetAttributes(this, workspacePath); + proxyModelFolderTree = new InventoryProxyModel(this, true); + proxyModelFileList = new InventoryProxyModel(this, false); + + proxyModelFolderTree->setSourceModel(invModel); + proxyModelFileList->setSourceModel(invModel); + + connect( + invModel, SIGNAL(invalidWorkspaceFormat(const QString &)), + this, SLOT(invalidWorkspaceFormat(const QString &)) + ); + + connect( + dialogManager, SIGNAL(revisionCommitted(const QString &)), + invModel, SIGNAL(readInventory()) + ); + + connect( + menuBar, SIGNAL(reloadWorkspace()), + invModel, SLOT(readInventory()) + ); + + connect( + menuBar, SIGNAL(hideIgnoredFiles(bool)), + proxyModelFileList, SLOT(setHideIgnoredFiles(bool)) + ); + + connect( + menuBar, SIGNAL(hideIgnoredFiles(bool)), + proxyModelFolderTree, SLOT(setHideIgnoredFiles(bool)) + ); + + connect( + menuBar, SIGNAL(filterFiles(int)), + proxyModelFileList, SLOT(setViewOption(int)) + ); + + connect( + menuBar, SIGNAL(filterFiles(int)), + proxyModelFolderTree, SLOT(setViewOption(int)) + ); + + treeView->setModel(proxyModelFolderTree); + listView->setModel(proxyModelFileList); + attrView->setModel(attrModel); +} + +bool WorkspaceWindow::load(const QString & path) +{ + try + { + workspacePath = MonotoneManager::normalizeWorkspacePath(path); + APP->manager()->getThreadForWorkspace(workspacePath); + } + catch (GuitoneException e) + { + QMessageBox::critical( + this, + tr("Failed to load workspace"), + tr("The workspace could not be loaded:\n%1").arg(e), + QMessageBox::Ok + ); + + // remove the workspace if it was recorded as recent workspace + Settings::removeItemFromList("RecentWorkspaceList", workspacePath); + return false; + } + + // read the inventory + invModel->readInventory(); + + // initialize the dialog manager + reinterpret_cast(dialogManager)->init(workspacePath); + + setWindowTitle( + tr("%1 - workspace mode - guitone"). + arg(MonotoneUtil::getBranchNameShort(workspacePath)) + ); + + Settings::addItemToList("RecentWorkspaceList", workspacePath, 5); + + return true; +} + +void WorkspaceWindow::openFile(const QString & filePath) +{ + QFileInfo file(workspacePath + "/" + filePath); + if (!file.exists()) + { + QMessageBox::critical( + this, + tr("Error"), + tr("The file you're trying to open does not exist."), + QMessageBox::Ok, 0, 0 + ); + return; + } + + if (!Platform::openFile(this, file.absoluteFilePath())) + { + QMessageBox::critical( + this, + tr("Error"), + tr("Unable to open files on your platform - please contact the " + "author about this problem."), + QMessageBox::Ok, 0, 0 + ); + } +} + +//! FIXME the dialog should query the data itself or retrieve from some global cache: +void WorkspaceWindow::checkForUnaccountedRenames() +{ + QMap renames = invModel->findUnaccountedRenames(); + if (renames.size() == 0) + { + QMessageBox::information( + this, + tr("Nothing found"), + tr("No unaccounted renames found for this workspace."), + QMessageBox::Ok + ); + return; + } + + reinterpret_cast(dialogManager) + ->showUnaccountedRenames(renames); +} + +void WorkspaceWindow::readAttributes(const QModelIndex & index) +{ + QModelIndex sourceIndex = static_cast(index.model())->mapToSource(index); + InventoryItem * item = static_cast(sourceIndex.internalPointer()); + + if (item->isRootDirectory() || item->isCdUp()) + { + D("item is pseudo item (root or cdup)"); + attrModel->revert(); + return; + } + + if (item->hasStatus(InventoryItem::Dropped) || !item->isTracked()) + { + D("item is not tracked or dropped"); + attrModel->revert(); + return; + } + + attrModel->readAttributes(item->getPath()); +} + ============================================================ --- src/view/WorkspaceWindow.h 9f25aaa1b7dabd9f27b282231971212351c12b28 +++ src/view/WorkspaceWindow.h 9f25aaa1b7dabd9f27b282231971212351c12b28 @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef WORKSPACEWINDOW_H +#define WORKSPACEWINDOW_H + +#include "DatabaseWindow.h" + +#include "Inventory.h" +#include "InventoryProxyModel.h" +#include "GetAttributes.h" + +#include "InventoryView.h" +#include "AttributesView.h" +#include "Splitter.h" + +class WorkspaceWindow: public DatabaseWindow +{ + Q_OBJECT +public: + WorkspaceWindow(); + ~WorkspaceWindow(); + + virtual void init(); + virtual bool load(const QString &); + +protected: + WorkspacePath workspacePath; + + Splitter * mainSplitter; + Splitter * listSplitter; + InventoryView * treeView; + InventoryView * listView; + AttributesView * attrView; + + Inventory * invModel; + GetAttributes * attrModel; + InventoryProxyModel * proxyModelFolderTree; + InventoryProxyModel * proxyModelFileList; + +private: + void readAttributes(const QModelIndex &); + void invalidWorkspaceFormat(const QString &); + void openFile(const QString &); + +private slots: + void checkForUnaccountedRenames(); +}; + +#endif