Little corrections for history handling

This commit is contained in:
Abs62 2012-09-12 21:19:21 +04:00
parent e00415e4d2
commit 78d450e1ca
3 changed files with 21 additions and 17 deletions

View file

@ -650,9 +650,6 @@ Class load() throw( exError )
if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() ) if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() )
c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt() ; c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt() ;
if ( !preferences.namedItem( "historyExportPath" ).isNull() )
c.preferences.historyExportPath = preferences.namedItem( "historyExportPath" ).toElement().text();
if ( !preferences.namedItem( "storeHistory" ).isNull() ) if ( !preferences.namedItem( "storeHistory" ).isNull() )
c.preferences.storeHistory = preferences.namedItem( "storeHistory" ).toElement().text().toUInt() ; c.preferences.storeHistory = preferences.namedItem( "storeHistory" ).toElement().text().toUInt() ;
} }
@ -697,6 +694,9 @@ Class load() throw( exError )
if ( !root.namedItem( "maxDictionaryRefsInContextMenu" ).isNull() ) if ( !root.namedItem( "maxDictionaryRefsInContextMenu" ).isNull() )
c.maxDictionaryRefsInContextMenu = root.namedItem( "maxDictionaryRefsInContextMenu" ).toElement().text().toUShort(); c.maxDictionaryRefsInContextMenu = root.namedItem( "maxDictionaryRefsInContextMenu" ).toElement().text().toUShort();
if ( !root.namedItem( "historyExportPath" ).isNull() )
c.historyExportPath = root.namedItem( "historyExportPath" ).toElement().text();
return c; return c;
} }
@ -1218,12 +1218,6 @@ void save( Class const & c ) throw( exError )
opt.appendChild( dd.createTextNode( QString::number( c.preferences.storeHistory ) ) ); opt.appendChild( dd.createTextNode( QString::number( c.preferences.storeHistory ) ) );
preferences.appendChild( opt ); preferences.appendChild( opt );
if( !c.preferences.historyExportPath.isEmpty() )
{
opt = dd.createElement( "historyExportPath" );
opt.appendChild( dd.createTextNode( c.preferences.historyExportPath ) );
preferences.appendChild( opt );
}
} }
{ {
@ -1274,6 +1268,13 @@ void save( Class const & c ) throw( exError )
opt = dd.createElement( "maxDictionaryRefsInContextMenu" ); opt = dd.createElement( "maxDictionaryRefsInContextMenu" );
opt.appendChild( dd.createTextNode( QString::number( c.maxDictionaryRefsInContextMenu ) ) ); opt.appendChild( dd.createTextNode( QString::number( c.maxDictionaryRefsInContextMenu ) ) );
root.appendChild( opt ); root.appendChild( opt );
if( !c.historyExportPath.isEmpty() )
{
opt = dd.createElement( "historyExportPath" );
opt.appendChild( dd.createTextNode( c.historyExportPath ) );
root.appendChild( opt );
}
} }
QByteArray result( dd.toByteArray() ); QByteArray result( dd.toByteArray() );

View file

@ -181,7 +181,6 @@ struct Preferences
int wordsZoomLevel; int wordsZoomLevel;
unsigned maxStringsInHistory; unsigned maxStringsInHistory;
QString historyExportPath;
unsigned storeHistory; unsigned storeHistory;
Preferences(); Preferences();
@ -372,6 +371,8 @@ struct Class
QByteArray popupWindowState; // Binary state saved by QMainWindow QByteArray popupWindowState; // Binary state saved by QMainWindow
QByteArray popupWindowGeometry; // Geometry saved by QMainWindow QByteArray popupWindowGeometry; // Geometry saved by QMainWindow
QString historyExportPath; // Path for export/import history
bool pinPopupWindow; // Last pin status bool pinPopupWindow; // Last pin status
QByteArray mainWindowState; // Binary state saved by QMainWindow QByteArray mainWindowState; // Binary state saved by QMainWindow

View file

@ -2705,11 +2705,11 @@ static bool needHideSearchPane;
void MainWindow::on_exportHistory_activated() void MainWindow::on_exportHistory_activated()
{ {
QString exportPath; QString exportPath;
if( cfg.preferences.historyExportPath.isEmpty() ) if( cfg.historyExportPath.isEmpty() )
exportPath = QDir::homePath(); exportPath = QDir::homePath();
else else
{ {
exportPath = QDir::fromNativeSeparators( cfg.preferences.historyExportPath ); exportPath = QDir::fromNativeSeparators( cfg.historyExportPath );
if( !QDir( exportPath ).exists() ) if( !QDir( exportPath ).exists() )
exportPath = QDir::homePath(); exportPath = QDir::homePath();
} }
@ -2720,7 +2720,7 @@ void MainWindow::on_exportHistory_activated()
if( fileName.size() == 0) if( fileName.size() == 0)
return; return;
cfg.preferences.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() ); cfg.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
QFile file( fileName ); QFile file( fileName );
for(;;) for(;;)
@ -2766,11 +2766,11 @@ void MainWindow::on_exportHistory_activated()
void MainWindow::on_importHistory_activated() void MainWindow::on_importHistory_activated()
{ {
QString importPath; QString importPath;
if( cfg.preferences.historyExportPath.isEmpty() ) if( cfg.historyExportPath.isEmpty() )
importPath = QDir::homePath(); importPath = QDir::homePath();
else else
{ {
importPath = QDir::fromNativeSeparators( cfg.preferences.historyExportPath ); importPath = QDir::fromNativeSeparators( cfg.historyExportPath );
if( !QDir( importPath ).exists() ) if( !QDir( importPath ).exists() )
importPath = QDir::homePath(); importPath = QDir::homePath();
} }
@ -2782,7 +2782,7 @@ void MainWindow::on_importHistory_activated()
return; return;
QFileInfo fileInfo( fileName ); QFileInfo fileInfo( fileName );
cfg.preferences.historyExportPath = QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() ); cfg.historyExportPath = QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() );
QString errStr; QString errStr;
QFile file( fileName ); QFile file( fileName );
@ -2884,8 +2884,10 @@ void MainWindow::forceAddWordToHistory( const QString & word )
fillWordListFromHistory(); fillWordListFromHistory();
if( index < 0 || index >= ui.wordList->count() || currentWord.compare( ui.wordList->item( index )->text() ) != 0 ) if( index < 0 || index >= ui.wordList->count() )
index = 0; index = 0;
if( index && currentWord.compare( ui.wordList->item( index )->text() ) != 0 )
index = currentWord.compare( ui.wordList->item( index - 1 )->text() ) == 0 ? index - 1 : 0;
if( index ) if( index )
disconnect( ui.wordList, SIGNAL( itemSelectionChanged() ), disconnect( ui.wordList, SIGNAL( itemSelectionChanged() ),