[yast-commit] r55262 - in /trunk/qt-pkg/src: YQPackageSelector.cc YQPkgFilterTab.cc YQPkgFilterTab.h
![](https://seccdn.libravatar.org/avatar/d788d4d6ea7d5ed777eaa8feaaa2c1d8.jpg?s=120&d=mm&r=g)
Author: sh-sh-sh Date: Wed Feb 4 18:24:22 2009 New Revision: 55262 URL: http://svn.opensuse.org/viewcvs/yast?rev=55262&view=rev Log: save and restore open tabs Modified: trunk/qt-pkg/src/YQPackageSelector.cc trunk/qt-pkg/src/YQPkgFilterTab.cc trunk/qt-pkg/src/YQPkgFilterTab.h Modified: trunk/qt-pkg/src/YQPackageSelector.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-pkg/src/YQPackageSelector.cc?rev=55262&r1=55261&r2=55262&view=diff ============================================================================== --- trunk/qt-pkg/src/YQPackageSelector.cc (original) +++ trunk/qt-pkg/src/YQPackageSelector.cc Wed Feb 4 18:24:22 2009 @@ -142,13 +142,16 @@ addMenus(); // Only after all widgets are created! makeConnections(); emit loadData(); + + _filters->loadSettings(); + bool pagesRestored = _filters->tabCount() > 0; if ( _pkgList ) _pkgList->clear(); if ( _patchFilterView && onlineUpdateMode() ) { - if ( _filters && _patchFilterView && _patchList ) + if ( _patchFilterView && _patchList ) { _filters->showPage( _patchFilterView ); _patchList->filter(); @@ -161,13 +164,6 @@ _filters->showPage( _repoFilterView ); _repoFilterView->filter(); } - else if ( _searchFilterView ) - { - yuiMilestone() << "No multiple repositories - falling back to search mode" << endl; - _filters->showPage( _searchFilterView ); - _searchFilterView->filter(); - QTimer::singleShot( 0, _searchFilterView, SLOT( setFocus() ) ); - } } else if ( _updateProblemFilterView ) { @@ -175,21 +171,27 @@ _updateProblemFilterView->filter(); } - else if ( searchMode() && _searchFilterView ) - { - _filters->showPage( _searchFilterView ); - _searchFilterView->filter(); - QTimer::singleShot( 0, _searchFilterView, SLOT( setFocus() ) ); - } - else if ( summaryMode() && _statusFilterView ) - { - _filters->showPage( _statusFilterView ); - _statusFilterView->filter(); - } - else if ( _patternList ) + + if ( ! pagesRestored ) { - _filters->showPage( _patternList ); - _patternList->filter(); + yuiDebug() << "No page configuration saved, using fallbacks" << endl; + + if ( searchMode() && _searchFilterView ) + { + _filters->showPage( _searchFilterView ); + _searchFilterView->filter(); + QTimer::singleShot( 0, _searchFilterView, SLOT( setFocus() ) ); + } + else if ( summaryMode() && _statusFilterView ) + { + _filters->showPage( _statusFilterView ); + _statusFilterView->filter(); + } + else if ( _patternList ) + { + _filters->showPage( _patternList ); + _patternList->filter(); + } } @@ -232,7 +234,12 @@ layout->setSpacing( SPACING_BELOW_MENU_BAR ); layoutMenuBar( this ); - _filters = new YQPkgFilterTab( this ); + QString settingsName = "pkg"; + + if ( onlineUpdateMode() ) settingsName = "online-update"; + if ( updateMode() ) settingsName = "system-update"; + + _filters = new YQPkgFilterTab( this, settingsName ); YUI_CHECK_NEW( _filters ); layout->addWidget( _filters ); @@ -255,9 +262,7 @@ { _updateProblemFilterView = new YQPkgUpdateProblemFilterView( parent ); YUI_CHECK_NEW( _updateProblemFilterView ); - _filters->addPage( _( "&Update Problems" ), _updateProblemFilterView, - "update_problems", // internal name - true ); // showAlways + _filters->addPage( _( "&Update Problems" ), _updateProblemFilterView, "update_problems" ); } } @@ -355,8 +360,7 @@ _searchFilterView = new YQPkgSearchFilterView( parent ); YUI_CHECK_NEW( _searchFilterView ); - _filters->addPage( _( "S&earch" ), _searchFilterView, "search", - true ); // showAlways + _filters->addPage( _( "S&earch" ), _searchFilterView, "search" ); @@ -372,8 +376,7 @@ _statusFilterView = new YQPkgStatusFilterView( parent ); YUI_CHECK_NEW( _statusFilterView ); - _filters->addPage( _( "&Installation Summary" ), _statusFilterView, "inst_summary", - true ); // showAlways + _filters->addPage( _( "&Installation Summary" ), _statusFilterView, "inst_summary" ); } Modified: trunk/qt-pkg/src/YQPkgFilterTab.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-pkg/src/YQPkgFilterTab.cc?rev=55262&r1=55261&r2=55262&view=diff ============================================================================== --- trunk/qt-pkg/src/YQPkgFilterTab.cc (original) +++ trunk/qt-pkg/src/YQPkgFilterTab.cc Wed Feb 4 18:24:22 2009 @@ -30,6 +30,7 @@ #include <QStackedWidget> #include <QTabBar> #include <QToolButton> +#include <QSettings> #define YUILogComponent "qt-pkg" #include "YUILog.h" @@ -59,8 +60,9 @@ struct YQPkgFilterTabPrivate { - YQPkgFilterTabPrivate() - : baseClassWidgetStack(0) + YQPkgFilterTabPrivate( const QString & name ) + : settingsName( name ) + , baseClassWidgetStack(0) , outerSplitter(0) , leftPaneSplitter(0) , filtersWidgetStack(0) @@ -72,6 +74,7 @@ , tabContextMenuPage(0) {} + QString settingsName; QStackedWidget * baseClassWidgetStack; QSplitter * outerSplitter; QSplitter * leftPaneSplitter; @@ -91,9 +94,9 @@ -YQPkgFilterTab::YQPkgFilterTab( QWidget * parent ) +YQPkgFilterTab::YQPkgFilterTab( QWidget * parent, const QString & settingsName ) : QTabWidget( parent ) - , priv( new YQPkgFilterTabPrivate() ) + , priv( new YQPkgFilterTabPrivate( settingsName ) ) { YUI_CHECK_NEW( priv ); @@ -254,6 +257,8 @@ YQPkgFilterTab::~YQPkgFilterTab() { + saveSettings(); + for ( YQPkgFilterPageVector::iterator it = priv->pages.begin(); it != priv->pages.end(); ++it ) @@ -282,13 +287,11 @@ void YQPkgFilterTab::addPage( const QString & pageLabel, QWidget * pageContent, - const QString & internalName, - bool showAlways ) + const QString & internalName ) { YQPkgFilterPage * page = new YQPkgFilterPage( pageLabel, pageContent, - internalName, - showAlways ); + internalName ); YUI_CHECK_NEW( page ); priv->pages.push_back( page ); @@ -304,13 +307,10 @@ priv->viewButton->menu()->addAction( action ); } -#if SHOW_ONLY_IMPORTANT_PAGES - if ( showAlways ) +#if ! SHOW_ONLY_IMPORTANT_PAGES + page->tabIndex = tabBar()->addTab( pageLabel ); + priv->closeButton->setEnabled( tabBar()->count() > 1 && page->closeEnabled ); #endif - { - page->tabIndex = tabBar()->addTab( pageLabel ); - priv->closeButton->setEnabled( tabBar()->count() > 1 && page->closeEnabled ); - } } @@ -377,6 +377,25 @@ void +YQPkgFilterTab::closeAllPages() +{ + while ( tabBar()->count() > 0 ) + { + tabBar()->removeTab( 0 ); + } + + for ( YQPkgFilterPageVector::iterator it = priv->pages.begin(); + it != priv->pages.end(); + ++it ) + { + (*it)->tabIndex = -1; + } + + priv->closeButton->setEnabled( false ); +} + + +void YQPkgFilterTab::closeCurrentPage() { if ( tabBar()->count() > 1 ) @@ -590,13 +609,9 @@ tabBar()->setTabText( page1->tabIndex, page1->label ); tabBar()->setTabText( page2->tabIndex, page2->label ); - yuiDebug() << "Swapping tabs \"" << toUTF8( page1->label ) - << "\" and \"" << toUTF8( page2->label ) << "\"" - << endl; - // If one of the two pages was the currently displayed one, - // make sure the same one is still displayed + // make sure the same page is still displayed. if ( oldCurrentIndex == page1->tabIndex ) { @@ -641,6 +656,71 @@ } +void +YQPkgFilterTab::loadSettings() +{ + closeAllPages(); + QSettings settings( QSettings::UserScope, "openSUSE.org", priv->settingsName ); + + int size = settings.beginReadArray( "tab-pages" ); + + for ( int i=0; i < size; i++ ) + { + settings.setArrayIndex(i); + QString id = settings.value( "ID" ).toString(); + YQPkgFilterPage * page = findPage( id ); + + if ( page ) + { + yuiDebug() << "Restoring page \"" << toUTF8( id ) << "\"" << endl; + showPage( page ); + } + else + yuiWarning() << "No page with ID \"" << toUTF8( id ) << "\"" << endl; + } + + settings.endArray(); + + QString id = settings.value( "current-page" ).toString(); + + if ( ! id.isEmpty() ) + showPage( id ); +} -#include "YQPkgFilterTab.moc" +void +YQPkgFilterTab::saveSettings() +{ + QSettings settings( QSettings::UserScope, "openSUSE.org", priv->settingsName ); + + settings.beginWriteArray( "tab-pages" ); + + for ( int i=0; i < tabBar()->count(); i++ ) + { + YQPkgFilterPage * page = findPage( i ); + + if ( page ) + { + settings.setArrayIndex(i); + + if ( page->id.isEmpty() ) + yuiWarning() << "No ID for tab page \"" << page->label << "\"" << endl; + else + { + yuiDebug() << "Saving page #" << i << ": \"" << toUTF8( page->id ) << "\"" << endl; + settings.setValue( "ID", page->id ); + } + } + } + + settings.endArray(); + + YQPkgFilterPage * currentPage = findPage( tabBar()->currentIndex() ); + + if ( currentPage ) + settings.setValue( "current-page", currentPage->id ); +} + + + +#include "YQPkgFilterTab.moc" Modified: trunk/qt-pkg/src/YQPkgFilterTab.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-pkg/src/YQPkgFilterTab.h?rev=55262&r1=55261&r2=55262&view=diff ============================================================================== --- trunk/qt-pkg/src/YQPkgFilterTab.h (original) +++ trunk/qt-pkg/src/YQPkgFilterTab.h Wed Feb 4 18:24:22 2009 @@ -69,9 +69,9 @@ public: /** - * Constructor. + * Constructor. 'settingsName' is the name to use to save and load settings. **/ - YQPkgFilterTab( QWidget * parent ); + YQPkgFilterTab( QWidget * parent, const QString & settingsName ); /** * Destructor. @@ -80,16 +80,12 @@ /** * Add a page with a user-visible "pageLabel", a widget with the page - * content and an internal name (or ID). If 'showAlways' is true, the - * corresponding tab will be opened immediately, otherwise the page will - * just be added to the pop-up menu on the [New] button. - * + * content and an internal name (or ID). * 'pageContent' will be reparented to a subwidget of this class. **/ void addPage( const QString & pageLabel, QWidget * pageContent, - const QString & internalName = QString(), - bool showAlways = false ); + const QString & internalName ); /** * Return the right pane. @@ -134,7 +130,7 @@ **/ virtual bool eventFilter ( QObject * watchedObj, QEvent * event ); - + signals: /** @@ -157,7 +153,29 @@ **/ void closeCurrentPage(); - + /** + * Load settings, including which tabs are to be opened and in which order. + * Return 'true' if settings could be loaded, 'false' if not. + * + * Applications should call this after all pages have been added so the + * open tabs can be restored the same way as the user left the program. + * If tabCount() is still 0 afterwards, there were no settings, so it might + * make sense to open a number of default pages. + **/ + void loadSettings(); + + /** + * Save the current settings, including which tabs are currently open and + * in which order. This is implicitly done in the destructor. + **/ + void saveSettings(); + + /** + * Close all currently open pages. + **/ + void closeAllPages(); + + protected slots: /** @@ -172,22 +190,22 @@ /** * Move the current tab page (from the context menu) one position to the - * left. + * left. **/ void contextMovePageLeft(); - + /** * Move the current tab page (from the context menu) one position to the - * right. + * right. **/ void contextMovePageRight(); - + /** * Close the current tab page (from the context menu). **/ void contextClosePage(); - + protected: /** @@ -206,8 +224,8 @@ * Swap two tabs and adjust their tab indices accordingly. **/ void swapTabs( YQPkgFilterPage * page1, YQPkgFilterPage * page2 ); - - + + private: ImplPtr<YQPkgFilterTabPrivate> priv; @@ -222,12 +240,10 @@ { YQPkgFilterPage( const QString & pageLabel, QWidget * content, - const QString & internalName = QString(), - bool showAlways = false ) + const QString & internalName ) : content( content ) , label( pageLabel ) , id( internalName ) - , showAlways( showAlways ) , closeEnabled( true ) , tabIndex( -1 ) {} @@ -235,7 +251,6 @@ QWidget * content; QString label; // user visible text QString id; // internal name - bool showAlways; bool closeEnabled; int tabIndex; // index of the corresponding tab or -1 if none }; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org