Export history to file

This commit is contained in:
Abs62 2012-02-17 16:01:52 +04:00
parent 11561ac4af
commit efba96f0d6
3 changed files with 58 additions and 0 deletions

View file

@ -2597,3 +2597,53 @@ static bool needHideSearchPane;
ui.wordList->setUpdatesEnabled( true ); ui.wordList->setUpdatesEnabled( true );
} }
} }
void MainWindow::on_exportHistory_activated()
{
QString fileName = QFileDialog::getSaveFileName( this, tr( "Export history to file" ),
QDir::homePath(),
tr( "Text files (*.txt);;All files (*.*)" ) );
if( fileName.size() == 0)
return;
QFile file( fileName );
for(;;)
{
if ( !file.open( QFile::WriteOnly | QIODevice::Text ) )
break;
// Write UTF-8 BOM
QByteArray line;
line.append( 0xEF ).append( 0xBB ).append( 0xBF );
if ( file.write( line ) != line.size() )
break;
// Write history
QList< History::Item > const & items = history.getItems();
QList< History::Item >::const_iterator i;
for( i = items.constBegin(); i != items.constEnd(); ++i )
{
line = i->word.toUtf8();
line.replace( '\n', ' ' );
line.replace( '\r', ' ' );
line += "\n";
if ( file.write( line ) != line.size() )
break;
}
if( i != items.constEnd() )
break;
file.close();
mainStatusBar->showMessage( tr( "History export complete" ), 5000 );
return;
}
QString errStr = QString( tr( "Export error: ") ) + file.errorString();
file.close();
mainStatusBar->showMessage( errStr, 10000, QPixmap( ":/icons/error.png" ) );
}

View file

@ -319,6 +319,7 @@ private slots:
void on_rescanFiles_activated(); void on_rescanFiles_activated();
void on_showHideHistory_activated(); void on_showHideHistory_activated();
void on_exportHistory_activated();
}; };
#endif #endif

View file

@ -115,6 +115,8 @@
<string>H&amp;istory</string> <string>H&amp;istory</string>
</property> </property>
<addaction name="showHideHistory"/> <addaction name="showHideHistory"/>
<addaction name="exportHistory"/>
<addaction name="separator"/>
<addaction name="clearHistory"/> <addaction name="clearHistory"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
@ -416,6 +418,11 @@
<string>&amp;Show</string> <string>&amp;Show</string>
</property> </property>
</action> </action>
<action name="exportHistory">
<property name="text">
<string>&amp;Export</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>