mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24: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 );
|
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_rescanFiles_activated();
|
||||||
|
|
||||||
void on_showHideHistory_activated();
|
void on_showHideHistory_activated();
|
||||||
|
void on_exportHistory_activated();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -115,6 +115,8 @@
|
||||||
<string>H&istory</string>
|
<string>H&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>&Show</string>
|
<string>&Show</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="exportHistory">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Export</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Reference in a new issue