+ Implement saving and restoring of the last chosen groups.

This commit is contained in:
Konstantin Isakov 2009-02-06 17:04:11 +00:00
parent 8e43a81592
commit abc6d30d7c
8 changed files with 78 additions and 4 deletions

View file

@ -135,6 +135,9 @@ Class load() throw( exError )
c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() );
}
c.lastMainGroup = root.namedItem( "lastMainGroup" ).toElement().text();
c.lastPopupGroup = root.namedItem( "lastPopupGroup" ).toElement().text();
return c;
}
@ -231,6 +234,16 @@ void save( Class const & c ) throw( exError )
preferences.appendChild( opt );
}
{
QDomElement opt = dd.createElement( "lastMainGroup" );
opt.appendChild( dd.createTextNode( c.lastMainGroup ) );
root.appendChild( opt );
opt = dd.createElement( "lastPopupGroup" );
opt.appendChild( dd.createTextNode( c.lastPopupGroup ) );
root.appendChild( opt );
}
configFile.write( dd.toByteArray() );
}

View file

@ -44,6 +44,9 @@ struct Class
Paths paths;
Groups groups;
Preferences preferences;
QString lastMainGroup; // Last used group in main window
QString lastPopupGroup; // Last used group in popup window
};
DEF_EX( exError, "Error with the program's configuration", std::exception )

View file

@ -26,3 +26,15 @@ void GroupComboBox::fill( Instances::Groups const & groups )
}
}
void GroupComboBox::setCurrentGroup( QString const & gr )
{
for( int x = 0; x < count(); ++x )
{
if ( itemText( x ) == gr )
{
setCurrentIndex( x );
break;
}
}
}

View file

@ -18,6 +18,10 @@ public:
/// Fills combo-box with the given groups
void fill( Instances::Groups const & );
/// Chooses the given group in the combobox. If there's no such group,
/// does nothing.
void setCurrentGroup( QString const & );
};
#endif

View file

@ -81,6 +81,9 @@ MainWindow::MainWindow():
connect( ui.preferences, SIGNAL( activated() ),
this, SLOT( editPreferences() ) );
connect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
this, SLOT( currentGroupChanged( QString const & ) ) );
connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ),
this, SLOT( translateInputChanged( QString const & ) ) );
@ -103,6 +106,12 @@ MainWindow::MainWindow():
show();
}
MainWindow::~MainWindow()
{
// Save any changes in last chosen groups etc
Config::save( cfg );
}
LoadDictionaries::LoadDictionaries( vector< string > const & allFiles_ ):
allFiles( allFiles_ )
{
@ -295,6 +304,11 @@ void MainWindow::updateGroupList()
ui.groupLabel->setText( haveGroups ? tr( "Look up in:" ) : tr( "Look up:" ) );
// currentIndexChanged() signal is very trigger-happy. To avoid triggering
// it, we disconnect it while we're clearing and filling back groups.
disconnect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
this, SLOT( currentGroupChanged( QString const & ) ) );
{
DictLock _;
@ -305,6 +319,10 @@ void MainWindow::updateGroupList()
}
ui.groupList->fill( groupInstances );
ui.groupList->setCurrentGroup( cfg.lastMainGroup );
connect( ui.groupList, SIGNAL( currentIndexChanged( QString const & ) ),
this, SLOT( currentGroupChanged( QString const & ) ) );
}
void MainWindow::makeScanPopup()
@ -449,6 +467,15 @@ void MainWindow::editPreferences()
}
}
void MainWindow::currentGroupChanged( QString const & gr )
{
cfg.lastMainGroup = gr;
// Update word search results
translateInputChanged( ui.translateLine->text() );
}
void MainWindow::translateInputChanged( QString const & newValue )
{
QString req = newValue.trimmed();
@ -500,7 +527,10 @@ void MainWindow::prefixMatchComplete( WordFinderResults r )
}
if ( ui.wordList->count() )
{
ui.wordList->scrollToItem( ui.wordList->item( 0 ), QAbstractItemView::PositionAtTop );
ui.wordList->setCurrentItem( 0, QItemSelectionModel::Clear );
}
ui.wordList->setUpdatesEnabled( true );
ui.wordList->unsetCursor();
@ -614,6 +644,12 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason )
{
if ( !isVisible() )
show();
else
if ( isMinimized() )
{
showNormal();
activateWindow();
}
else
hide();
}

View file

@ -56,6 +56,7 @@ class MainWindow: public QMainWindow
public:
MainWindow();
~MainWindow();
private:
@ -113,6 +114,7 @@ private slots:
void editPreferences();
void indexingDictionary( QString dictionaryName );
void currentGroupChanged( QString const & );
void translateInputChanged( QString const & );
void prefixMatchComplete( WordFinderResults );
void wordListItemActivated( QListWidgetItem * );

View file

@ -14,7 +14,7 @@
using std::wstring;
ScanPopup::ScanPopup( QWidget * parent,
Config::Class const & cfg_,
Config::Class & cfg_,
ArticleNetworkAccessManager & articleNetMgr,
std::vector< sptr< Dictionary::Class > > const & allDictionaries_,
Instances::Groups const & groups_ ):
@ -33,6 +33,8 @@ ScanPopup::ScanPopup( QWidget * parent,
ui.prefixButton->hide();
ui.groupList->fill( groups );
ui.groupList->setCurrentGroup( cfg.lastPopupGroup );
setWindowFlags( Qt::Popup );
#ifdef Q_OS_WIN32
@ -131,10 +133,12 @@ QString ScanPopup::elideInputWord()
}
void ScanPopup::currentGroupChanged( QString const & )
void ScanPopup::currentGroupChanged( QString const & gr )
{
if ( isVisible() )
initiateTranslation();
cfg.lastPopupGroup = gr;
}
void ScanPopup::initiateTranslation()

View file

@ -22,14 +22,14 @@ class ScanPopup: public QDialog, KeyboardState
public:
ScanPopup( QWidget * parent,
Config::Class const & cfg,
Config::Class & cfg,
ArticleNetworkAccessManager &,
std::vector< sptr< Dictionary::Class > > const & allDictionaries,
Instances::Groups const & );
private:
Config::Class const & cfg;
Config::Class & cfg;
std::vector< sptr< Dictionary::Class > > const & allDictionaries;
Instances::Groups const & groups;
Ui::ScanPopup ui;