mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Export history to file
This commit is contained in:
parent
11561ac4af
commit
efba96f0d6
|
@ -2597,3 +2597,53 @@ static bool needHideSearchPane;
|
|||
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" ) );
|
||||
}
|
||||
|
|
|
@ -319,6 +319,7 @@ private slots:
|
|||
void on_rescanFiles_activated();
|
||||
|
||||
void on_showHideHistory_activated();
|
||||
void on_exportHistory_activated();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
<string>H&istory</string>
|
||||
</property>
|
||||
<addaction name="showHideHistory"/>
|
||||
<addaction name="exportHistory"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="clearHistory"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
|
@ -416,6 +418,11 @@
|
|||
<string>&Show</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="exportHistory">
|
||||
<property name="text">
|
||||
<string>&Export</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Reference in a new issue