diff options
author | Daniel Burrows <dburrows@debian.org> | 2010-07-19 18:43:36 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2010-07-19 18:43:36 -0700 |
commit | 9d1ff0a40b5bbbb661415a17a02cc4bcb0711a28 (patch) | |
tree | f590421493dd5e41d23a37475380af74a92907b3 /src | |
parent | 9d2b3a91cafd61ab8c973629153017489e9d2e67 (diff) | |
parent | b7c0e95463426381865ac9902d73260e4ad284ff (diff) | |
download | aptitude-9d1ff0a40b5bbbb661415a17a02cc4bcb0711a28.tar.gz |
Merge commit 'b7c0e95463426381865ac9902d73260e4ad284ff'
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/Makefile.am | 11 | ||||
-rw-r--r-- | src/qt/qt_main.cc | 22 | ||||
-rw-r--r-- | src/qt/widgets/status_widget.cc | 149 | ||||
-rw-r--r-- | src/qt/widgets/status_widget.h | 131 | ||||
-rw-r--r-- | src/qt/widgets/tab_widget.cc | 126 | ||||
-rw-r--r-- | src/qt/widgets/tab_widget.h | 104 | ||||
-rw-r--r-- | src/qt/windows/main_window.cc | 119 | ||||
-rw-r--r-- | src/qt/windows/main_window.h | 88 |
8 files changed, 744 insertions, 6 deletions
diff --git a/src/qt/Makefile.am b/src/qt/Makefile.am index ce2e32cc..23ecd7c9 100644 --- a/src/qt/Makefile.am +++ b/src/qt/Makefile.am @@ -12,7 +12,10 @@ libqt_a_MOC = \ widgets/packages_tab.moc \ widgets/perform_changes_tab.moc \ widgets/resolver_tab.moc \ - widgets/tab.moc + widgets/status_widget.moc \ + widgets/tab.moc \ + widgets/tab_widget.moc \ + windows/main_window.moc libqt_a_SOURCES= \ widgets/changes_preview_tab.cc \ @@ -25,8 +28,14 @@ libqt_a_SOURCES= \ widgets/perform_changes_tab.h \ widgets/resolver_tab.cc \ widgets/resolver_tab.h \ + widgets/status_widget.cc \ + widgets/status_widget.h \ widgets/tab.cc \ widgets/tab.h \ + widgets/tab_widget.cc \ + widgets/tab_widget.h \ + windows/main_window.cc \ + windows/main_window.h \ qt_main.cc \ qt_main.h diff --git a/src/qt/qt_main.cc b/src/qt/qt_main.cc index 6b04c795..bd6030f4 100644 --- a/src/qt/qt_main.cc +++ b/src/qt/qt_main.cc @@ -19,10 +19,16 @@ // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. -#include <signal.h> - +// Local includes #include "qt_main.h" +#include "windows/main_window.h" + +// System includes +#include <QtGui/QApplication> + +#include <signal.h> + namespace aptitude { namespace gui @@ -31,10 +37,16 @@ namespace aptitude { bool main(int argc, char **argv) { - // Don't crash if a subprocess breaks a pipe. - signal(SIGPIPE, SIG_IGN); + // Don't crash if a subprocess breaks a pipe. + signal(SIGPIPE, SIG_IGN); + + QApplication app(argc,argv); + + main_window *main = new main_window; + main->show(); - return true; + app.exec(); + return true; } } } diff --git a/src/qt/widgets/status_widget.cc b/src/qt/widgets/status_widget.cc new file mode 100644 index 00000000..31c57f97 --- /dev/null +++ b/src/qt/widgets/status_widget.cc @@ -0,0 +1,149 @@ +/** \file status_widget.cc */ +// +// Copyright (C) 2010 Piotr Galiszewski +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Local includes +#include "status_widget.h" + +// System includes +#include <QtGui/QApplication> +#include <QtGui/QDialogButtonBox> +#include <QtGui/QLabel> +#include <QtGui/QPushButton> +#include <QtGui/QStackedWidget> +#include <QtGui/QStyle> +#include <QtGui/QVBoxLayout> + +namespace aptitude +{ + namespace gui + { + namespace qt + { + status_widget::status_widget(QWidget *parent) + : QWidget(parent) + { + create_gui(); + + update_changes_summary(); + } + + status_widget::~status_widget() + { + } + + void status_widget::create_gui() + { + stacked_widget = new QStackedWidget(); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(stacked_widget); + + create_changes_widget(); + create_progress_widget(); + } + + void status_widget::create_changes_widget() + { + changes_widget = new QWidget(); + + QHBoxLayout *main_layout = new QHBoxLayout(changes_widget); + + changes_summary = new QLabel(); + main_layout->addWidget(changes_summary); + + QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal, this); + main_layout->addWidget(buttons); + + // TODO: find proper icons + show_changes_button = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogApplyButton), "Show Changes", this); + apply_changes_button = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogApplyButton), "Apply Changes", this); + resolve_dependencies_button = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogApplyButton), "Resolve Dependeincies", this); + cancel_button = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogCancelButton), "Cancel", this); + + connect(show_changes_button, SIGNAL(clicked()), this, SLOT(show_changes_button_clicked())); + connect(apply_changes_button, SIGNAL(clicked()), this, SLOT(apply_changes_button_clicked())); + connect(resolve_dependencies_button, SIGNAL(clicked()), this, SLOT(resolve_dependencies_button_clicked())); + connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancel_button_clicked())); + + buttons->addButton(show_changes_button, QDialogButtonBox::ApplyRole); + buttons->addButton(apply_changes_button, QDialogButtonBox::ApplyRole); + buttons->addButton(resolve_dependencies_button, QDialogButtonBox::ApplyRole); + buttons->addButton(cancel_button, QDialogButtonBox::RejectRole); + + stacked_widget->addWidget(changes_widget); + } + + void status_widget::create_progress_widget() + { + progress_widget = new QWidget(); + + stacked_widget->addWidget(progress_widget); + } + + void status_widget::update_changes_summary() + { + changes_summary->setText("Short changes summary"); + + resolve_dependencies_button->hide(); + show_changes_button->setEnabled(false); + apply_changes_button->setEnabled(false); + + } + + void status_widget::apply_changes_button_clicked() + { + } + + void status_widget::cancel_button_clicked() + { + } + + void status_widget::resolve_dependencies_button_clicked() + { + } + + void status_widget::show_changes_button_clicked() + { + } + + // TODO: add proper logic hear + void status_widget::current_tab_changed(tab::tab_type type) + { + if(type == tab::tab_resolver) + { + apply_changes_button->show(); + resolve_dependencies_button->hide(); + } + else if(type == tab::tab_preview) + { + show_changes_button->setEnabled(false); + apply_changes_button->hide(); + resolve_dependencies_button->show(); + } + else + { + apply_changes_button->hide(); + resolve_dependencies_button->show(); + } + } + } + } +} + +#include "status_widget.moc" diff --git a/src/qt/widgets/status_widget.h b/src/qt/widgets/status_widget.h new file mode 100644 index 00000000..0d784db4 --- /dev/null +++ b/src/qt/widgets/status_widget.h @@ -0,0 +1,131 @@ +/** \file status_widget.h */ // -*-c++-*- +// +// Copyright (C) 2010 Piotr Galiszewski +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef APTITUDE_QT_STATUS_WIDGET_H +#define APTITUDE_QT_STATUS_WIDGET_H + +// Local includes +#include "tab.h" + +// System includes +#include <QtGui/QWidget> + +class QLabel; +class QPushButton; +class QStackedWidget; + +namespace aptitude +{ + namespace gui + { + namespace qt + { + /** \brief Widget showing informations about current state of the program. + * + * This widget is always displayed at the bottom of the main window and + * is divided into two parts. + * The first part shows infromations about requested changes of package + * state, and the second part shows progress of currently running program's + * activites. At the top of the widget, name of the last finished activity + * is displayed. + * + * Widgets are placed in QStackedWidget, so only one of those widgets can be shown + * at the same time + */ + class status_widget : public QWidget + { + Q_OBJECT + + QPushButton *show_changes_button; + QPushButton *apply_changes_button; + QPushButton *cancel_button; + QPushButton *resolve_dependencies_button; + + QLabel *changes_summary; + + QWidget *changes_widget; + QWidget *progress_widget; + + QStackedWidget *stacked_widget; + + /** \brief Create layouts and widgets. */ + void create_gui(); + + /** \brief Create layout and widget of changes preview widget. */ + void create_changes_widget(); + + /** \brief Create layout and widget of progress widget. */ + void create_progress_widget(); + + /** \brief Update an information about requested changes in package cache. */ + void update_changes_summary(); + + private Q_SLOTS: + /** \brief Slot triggered when the Show Changes button has been clicked + * by the user + * + * This slot creates new (or make active if tab is already present) + * Changes Preview tab + */ + void show_changes_button_clicked(); + + /** \brief Slot triggered when the Apply Changes button has been clicked + * by the user + * + * This slots starts a process of appling changes + */ + void apply_changes_button_clicked(); + + /** \brief Slot triggered when the Resolve Dependencies button has been clicked + * by the user + * + * This slot creates new (or make active if tab is already present) + * Resolver tab + */ + void resolve_dependencies_button_clicked(); + + /** \brief Slot triggered when the Cancel button has been clicked + * by the user + * + * This slot aborts curranly running task + */ + void cancel_button_clicked(); + + public: + /** \brief Create a new status_widget object. */ + explicit status_widget(QWidget *parent = 0); + + /** \brief Destroy a status_widget object. */ + virtual ~status_widget(); + + public Q_SLOTS: + /** \brief Slot triggered when the current tab has changed + * on the main tab_widget + * + * The slot is responsible for enabling and disabling widget's buttons. + * For example when Changes Preview tab is active, Show Changes button should + * be disabled to not confuse the user + */ + void current_tab_changed(tab::tab_type type); + }; + } + } +} + +#endif // APTITUDE_QT_STATUS_WIDGET_H diff --git a/src/qt/widgets/tab_widget.cc b/src/qt/widgets/tab_widget.cc new file mode 100644 index 00000000..af102829 --- /dev/null +++ b/src/qt/widgets/tab_widget.cc @@ -0,0 +1,126 @@ +/** \file tab_widget.cc */ +// +// Copyright (C) 2010 Piotr Galiszewski +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include <QtGui/QTabBar> + +#include "tab_widget.h" + +namespace aptitude +{ + namespace gui + { + namespace qt + { + tab_widget::tab_widget(QWidget *parent) + : QTabWidget(parent) + { + setTabsClosable(true); + setUsesScrollButtons(true); + setMovable(true); + + connect(tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(tab_deletion_requested(int))); + connect(this, SIGNAL(currentChanged(int)), this, SLOT(on_tab_change(int))); + } + + tab_widget::~tab_widget() + { + for(int i=0; i<count(); ++i) + { + tab *tab_at_index = qobject_cast<tab *>(widget(i)); + + if(!tab_at_index) + return; + + Q_EMIT(tab_deletion_request(tab_at_index, true)); + + } + } + + void tab_widget::tab_deletion_requested(int index) + { + if(index < 0) + return; + + tab *tab_at_index = qobject_cast<tab *>(widget(index)); + + if(!tab_at_index) + return; + + Q_EMIT(tab_deletion_request(tab_at_index, false)); + } + + void tab_widget::set_tab_closable(tab *closable_tab, bool enabled) + { + int index = indexOf(closable_tab); + + if(index < 0) + return; + + tabBar()->tabButton(0, QTabBar::RightSide)->setEnabled(false); + } + + void tab_widget::on_tab_change(int index) + { + if(index < 0) + return; + + tab *tab_at_index = qobject_cast<tab *>(widget(index)); + + if(!tab_at_index) + return; + + Q_EMIT(current_tab_changed(tab_at_index->get_type())); + } + + void tab_widget::switch_tab_left() + { + if(currentIndex() == 0) + setCurrentIndex(count() - 1); + else + setCurrentIndex(currentIndex() - 1); + } + + void tab_widget::switch_tab_right() + { + if(currentIndex() == (count() - 1)) + setCurrentIndex(0); + else + setCurrentIndex(currentIndex() + 1); + } + + void tab_widget::key_pressed(QKeyEvent *e, bool &handled) + { + //TODO: make it configurable + if(handled) + return; + + //TODO: make shortcuts configurable and find good default values + handled = true; + if(true) + switch_tab_left(); + else if(false) + switch_tab_right(); + else + handled = false; + } + } + } +} + +#include "tab_widget.moc" diff --git a/src/qt/widgets/tab_widget.h b/src/qt/widgets/tab_widget.h new file mode 100644 index 00000000..5ef1008d --- /dev/null +++ b/src/qt/widgets/tab_widget.h @@ -0,0 +1,104 @@ +/** \file tab_widget.h */ // -*-c++-*- +// +// Copyright (C) 2010 Piotr Galiszewski +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef APTITUDE_QT_TAB_WIDGET_H +#define APTITUDE_QT_TAB_WIDGET_H + +#include <QtGui/QTabWidget> + +#include "tab.h" + +class QKeyEvent; + +namespace aptitude +{ + namespace gui + { + namespace qt + { + /** \brief Widget containing program's tabs. + * + * This widget is a central part of main program's window + * + * It is responsible for propagating signals about changing + * his state and responsing for user input (e.g. shortcuts or + * requests for closing tabs) + */ + class tab_widget : public QTabWidget + { + Q_OBJECT + + /** \brief Switches active tab to next tab on the left. */ + void switch_tab_left(); + + /** \brief Switches active tab to next tab on the right. */ + void switch_tab_right(); + + private Q_SLOTS: + /** \brief Slot invoked when user clicked on close button on + * tab with given index. + * + * Received signal is translated and propageted to the + * tabs_manager + */ + void tab_deletion_requested(int index); + + /** \brief Slot invoked when active tabs has changed + * + * Received signal is translated and propageted + */ + void on_tab_change(int index); + + public: + /** \brief Create new tab widget with the given parent */ + explicit tab_widget(QWidget *parent = 0); + + virtual ~tab_widget(); + + /** \brief Enable or disable close button on the given tab */ + void set_tab_closable(tab *closable_tab, bool enabled); + + public Q_SLOTS: + /** \brief Slot invoked when user typed a shortcut + * + * This slots translates key event to shortcut and checks + * if given shortcut is registered for this widget. + * If yes handled argument is set to true + */ + void key_pressed(QKeyEvent *e, bool &handled); + + Q_SIGNALS: + /** \brief Signal emitted when the current tab has changed. + * tab_type is a type of newly activated tab + */ + void current_tab_changed(tab::tab_type); + + /** \brief Signal emitted when user has requested closing + * closing given tab + * + * When the force parameter is true, the object has to be destroyed + * (this is true when tab_widget is going to be destroyed) + */ + void tab_deletion_request(tab *, bool force); + }; + } + } +} + +#endif // APTITUDE_QT_TAB_WIDGET_H diff --git a/src/qt/windows/main_window.cc b/src/qt/windows/main_window.cc new file mode 100644 index 00000000..7c4cc9dc --- /dev/null +++ b/src/qt/windows/main_window.cc @@ -0,0 +1,119 @@ +/** \file main_window.cc */ +// +// Copyright (C) 2010 Piotr Galiszewski +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +// Local includes +#include "main_window.h" + +#include "widgets/status_widget.h" +#include "widgets/tab_widget.h" + +#include "aptitude.h" + +// System includes +#include <QtGui/QMenu> +#include <QtGui/QMenuBar> +#include <QtGui/QVBoxLayout> + +namespace aptitude +{ + namespace gui + { + namespace qt + { + main_window::main_window() + { + setAttribute(Qt::WA_DeleteOnClose, true); + setWindowTitle(_("Aptitude Package Manager")); + + create_actions(); + create_menus(); + create_gui(); + + // TODO: Find a proper size. Add possibility do save user defined to config file. + // on the second run window should restore previous settings + setGeometry(0, 0, 640, 480); + } + + main_window::~main_window() + { + + } + + void main_window::create_actions() + { + + } + + void main_window::create_gui() + { + QWidget *main_widget = new QWidget(); + QVBoxLayout *main_layout = new QVBoxLayout(main_widget); + main_layout->setMargin(0); + main_layout->setSpacing(0); + + tabs = new tab_widget(); + status = new status_widget(); + + main_layout->addWidget(tabs); + main_layout->setStretchFactor(tabs, 100); + main_layout->addWidget(status); + + setCentralWidget(main_widget); + } + + void main_window::create_menus() + { + create_file_menu(); + create_packages_menu(); + create_help_menu(); + } + + void main_window::create_file_menu() + { + file_menu = new QMenu(); + file_menu->setTitle(_("&File")); + + menuBar()->addMenu(file_menu); + } + + void main_window::create_packages_menu() + { + packages_menu = new QMenu(); + packages_menu->setTitle(_("&Packages")); + + menuBar()->addMenu(packages_menu); + } + + void main_window::create_help_menu() + { + help_menu = new QMenu(); + help_menu->setTitle(_("&Help")); + + menuBar()->addMenu(help_menu); + } + + tab_widget *main_window::get_tab_widget() + { + return tabs; + } + } + } +} + +#include "main_window.moc" diff --git a/src/qt/windows/main_window.h b/src/qt/windows/main_window.h new file mode 100644 index 00000000..cc416c6c --- /dev/null +++ b/src/qt/windows/main_window.h @@ -0,0 +1,88 @@ +/** \file main_window.h */ // -*-c++-*- +// +// Copyright (C) 2010 Piotr Galiszewski +// +// 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; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include <QtGui/QMainWindow> + +class QMenu; + +namespace aptitude +{ + namespace gui + { + namespace qt + { + class status_widget; + class tab_widget; + + /** \brief Widget representing main window of the program. + * + * main_window is a central point of program. It is splitted + * into tree main parts: menu bar, tab widget and status widget + * + * menu bar is splitted into 3 parts and contains the most common + * program's actions + * + * Tab widget contains tabs. Each tab is responsible for one particular + * functionality of the program e.g. searching of packages or resolving + * conflicts + * + * Status widget shows state of the program (e.g. number of requested + * changes) and progress of active tasks + */ + class main_window : public QMainWindow + { + Q_OBJECT + + tab_widget *tabs; + status_widget *status; + + QMenu *file_menu; + QMenu *packages_menu; + QMenu *help_menu; + + /** \brief Create actions used in main menu and contexts menus. */ + void create_actions(); + + /** \brief Create layouts and widgets. */ + void create_gui(); + + /** \brief Create a main menu. */ + void create_menus(); + + /** \brief Create a file menu in main menu. */ + void create_file_menu(); + + /** \brief Create a help menu in main menu. */ + void create_help_menu(); + + /** \brief Create a packages menu in main menu. */ + void create_packages_menu(); + + public: + /** \brief Create a new main_window object. */ + explicit main_window(); + + virtual ~main_window(); + + /** \brief Retrieve a pointer to a tab_widget added to this window. */ + tab_widget *get_tab_widget(); + }; + } + } +} |