Skip to content

Commit

Permalink
opt: favorite panel ,unify the export txt&xml as one (#2031)
Browse files Browse the repository at this point in the history
* opt: unify the export txt&xml as one

* opt: remove all file filter
  • Loading branch information
xiaoyifang authored Dec 19, 2024
1 parent 5734c92 commit b9ab7dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 64 deletions.
80 changes: 23 additions & 57 deletions src/ui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3945,80 +3945,46 @@ void MainWindow::on_exportFavorites_triggered()
QString fileName = QFileDialog::getSaveFileName( this,
tr( "Export Favorites to file" ),
exportPath,
tr( "XML files (*.xml);;All files (*.*)" ) );
tr( "Text files (*.txt);;XML files (*.xml)" ) );
if ( fileName.size() == 0 ) {
return;
}

cfg.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
QFile file( fileName );


if ( !file.open( QFile::WriteOnly | QIODevice::Text ) ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}
if ( fileName.endsWith( ".xml", Qt::CaseInsensitive ) ) {
QByteArray data;
ui.favoritesPaneWidget->getDataInXml( data );

QByteArray data;
ui.favoritesPaneWidget->getDataInXml( data );

if ( file.write( data ) != data.size() ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}

file.close();
mainStatusBar->showMessage( tr( "Favorites export complete" ), 5000 );
}

void MainWindow::on_ExportFavoritesToList_triggered()
{
QString exportPath;
if ( cfg.historyExportPath.isEmpty() ) {
exportPath = QDir::homePath();
if ( file.write( data ) != data.size() ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}
}
else {
exportPath = QDir::fromNativeSeparators( cfg.historyExportPath );
if ( !QDir( exportPath ).exists() ) {
exportPath = QDir::homePath();
// Write UTF-8 BOM
QByteArray line;
line.append( 0xEF ).append( 0xBB ).append( 0xBF );
if ( file.write( line ) != line.size() ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}
}

QString fileName = QFileDialog::getSaveFileName( this,
tr( "Export Favorites to file as plain list" ),
exportPath,
tr( "Text files (*.txt);;All files (*.*)" ) );
if ( fileName.size() == 0 ) {
return;
}

cfg.historyExportPath = QDir::toNativeSeparators( QFileInfo( fileName ).absoluteDir().absolutePath() );
QFile file( fileName );
// Write Favorites
QString data;
ui.favoritesPaneWidget->getDataInPlainText( data );

if ( !file.open( QFile::WriteOnly | QIODevice::Text ) ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}

// Write UTF-8 BOM
QByteArray line;
line.append( 0xEF ).append( 0xBB ).append( 0xBF );
if ( file.write( line ) != line.size() ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}

// Write Favorites
QString data;
ui.favoritesPaneWidget->getDataInPlainText( data );

line = data.toUtf8();
if ( file.write( line ) != line.size() ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
line = data.toUtf8();
if ( file.write( line ) != line.size() ) {
errorMessageOnStatusBar( QString( tr( "Export error: " ) ) + file.errorString() );
return;
}
}

file.close();

mainStatusBar->showMessage( tr( "Favorites export complete" ), 5000 );
}

Expand Down
1 change: 0 additions & 1 deletion src/ui/mainwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ private slots:

void on_exportFavorites_triggered();
void on_importFavorites_triggered();
void on_ExportFavoritesToList_triggered();

void updateSearchPaneAndBar( bool searchInDock );

Expand Down
6 changes: 0 additions & 6 deletions src/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
</property>
<addaction name="showHideFavorites"/>
<addaction name="exportFavorites"/>
<addaction name="ExportFavoritesToList"/>
<addaction name="importFavorites"/>
<addaction name="separator"/>
<addaction name="actionAddToFavorites"/>
Expand Down Expand Up @@ -557,11 +556,6 @@
<string>Ctrl+E</string>
</property>
</action>
<action name="ExportFavoritesToList">
<property name="text">
<string>Export to list</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit b9ab7dc

Please sign in to comment.