1212
1313#include < QAbstractButton>
1414#include < QFile>
15+ #include < QLoggingCategory>
1516#include < QMessageBox>
1617#include < QShortcut>
1718
18- #include < memory>
19-
2019namespace {
2120
21+ Q_DECLARE_LOGGING_CATEGORY (logCategory)
22+ Q_LOGGING_CATEGORY (logCategory, " copyq.actiondialog" )
23+
2224void initFormatComboBox (QComboBox *combo, const QStringList &additionalFormats = QStringList())
2325{
2426 QStringList formats = QStringList () << QString () << QString (mimeText) << additionalFormats;
@@ -100,21 +102,29 @@ void ActionDialog::restoreHistory()
100102{
101103 const int maxCount = AppConfig ().option <Config::command_history_size>();
102104 ui->comboBoxCommands ->setMaxCount (maxCount + 1 );
105+ ui->comboBoxCommands ->clear ();
106+ ui->comboBoxCommands ->addItem (QString ());
107+ ui->comboBoxCommands ->setCurrentIndex (0 );
103108
104109 QFile file ( dataFilename () );
105- file.open (QIODevice::ReadOnly);
110+ if ( !file.exists () )
111+ return ;
112+
113+ if ( !file.open (QIODevice::ReadOnly) ) {
114+ qCWarning (logCategory) << " Failed to restore Action dialog history from"
115+ << file.fileName () << " :" << file.errorString ();
116+ return ;
117+ }
118+
106119 QDataStream in (&file);
107120 QVariant v;
108121
109- ui->comboBoxCommands ->clear ();
110- ui->comboBoxCommands ->addItem (QString ());
111122 while ( !in.atEnd () && ui->comboBoxCommands ->count () <= maxCount ) {
112123 in >> v;
113124 const QVariantMap values = v.value <QVariantMap>();
114125 const QString cmd = values.value (" cmd" ).toString ();
115126 ui->comboBoxCommands ->addItem ( commandToLabel (cmd), v );
116127 }
117- ui->comboBoxCommands ->setCurrentIndex (0 );
118128}
119129
120130const QString ActionDialog::dataFilename () const
@@ -125,7 +135,12 @@ const QString ActionDialog::dataFilename() const
125135void ActionDialog::saveHistory ()
126136{
127137 QFile file ( dataFilename () );
128- file.open (QIODevice::WriteOnly);
138+ if ( !file.open (QIODevice::WriteOnly) ) {
139+ qCWarning (logCategory) << " Failed to save Action dialog history to"
140+ << file.fileName () << " :" << file.errorString ();
141+ return ;
142+ }
143+
129144 QDataStream out (&file);
130145
131146 for (int i = 1 ; i < ui->comboBoxCommands ->count (); ++i) {
0 commit comments