diff --git a/src/aboutdlg.cpp b/src/aboutdlg.cpp index 8f1272e74..0df54b8cd 100644 --- a/src/aboutdlg.cpp +++ b/src/aboutdlg.cpp @@ -19,6 +19,7 @@ #include "aboutdlg.h" #include "applicationinfo.h" +#include "fileutil.h" #include "iconset.h" #include @@ -41,7 +42,7 @@ AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) + "

Copyright © 2001-2025 The Psi Team

"); ui_.lb_name->setText(QString("

%1 v%2

").arg(ApplicationInfo::name(), ApplicationInfo::version())); - ui_.te_license->setText(loadText(":/COPYING")); + ui_.te_license->setText(FileUtil::readFileText(":/COPYING")); QString lang_name = qApp->translate("@default", "language_name"); if (lang_name == "language_name") // remove the translation tab, if no translation is used @@ -125,21 +126,6 @@ AboutDlg::AboutDlg(QWidget *parent) : QDialog(parent) ui_.te_translation->appendText(translation); } -QString AboutDlg::loadText(const QString &fileName) -{ - QString text; - - QFile f(fileName); - if (f.open(QIODevice::ReadOnly)) { - QTextStream t(&f); - while (!t.atEnd()) - text += t.readLine() + '\n'; - f.close(); - } - - return text; -} - QString AboutDlg::details(QString name, QString email, QString xmppAddress, QString www, QString desc) { QString ret; diff --git a/src/aboutdlg.h b/src/aboutdlg.h index b8e6db835..896d46886 100644 --- a/src/aboutdlg.h +++ b/src/aboutdlg.h @@ -31,7 +31,6 @@ class AboutDlg : public QDialog { AboutDlg(QWidget *parent = nullptr); protected: - QString loadText(const QString &fileName); QString details(QString name, QString email, QString xmppAddress, QString www, QString desc); private: diff --git a/src/fileutil.cpp b/src/fileutil.cpp index ac543d436..2424426b1 100644 --- a/src/fileutil.cpp +++ b/src/fileutil.cpp @@ -33,6 +33,7 @@ #ifdef Q_OS_WIN #include #else +#include #include #endif @@ -160,7 +161,7 @@ QString FileUtil::getSaveDirName(QWidget *parent, const QString &caption) QString FileUtil::getImageFileName(QWidget *parent, QString caption) { - // double extenstions because of QTBUG-51712 + // double extensions because of QTBUG-51712 return FileUtil::getOpenFileName(parent, caption.isEmpty() ? tr("Choose a file") : caption, tr("Images (*.png *.xpm *.jpg *.jpeg *.webp *.PNG *.XPM *.JPG *.JPEG *.WEBP)")); } @@ -249,3 +250,43 @@ void FileUtil::setModificationTime(const QString &filename, const QDateTime &mti utime(filename.toLocal8Bit().data(), &t); #endif } + +QString FileUtil::readFileText(const QString &filename) +{ + QFile f(filename); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { + return ""; + } + QString text; + QTextStream in(&f); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + in.setEncoding(QStringConverter::Utf8); +#else + in.setCodec("UTF-8"); +#endif + while (!in.atEnd()) { + text += in.readLine() + '\n'; + } + f.close(); + return text; +} + +QStringList FileUtil::readFileLines(const QString &filename) { + QStringList lines; + QFile f(filename); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { + return lines; + } + QString text; + QTextStream in(&f); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + in.setEncoding(QStringConverter::Utf8); +#else + in.setCodec("UTF-8"); +#endif + while (!in.atEnd()) { + lines << in.readLine(); + } + f.close(); + return lines; +} \ No newline at end of file diff --git a/src/fileutil.h b/src/fileutil.h index beee4feff..ee3b9c1ac 100644 --- a/src/fileutil.h +++ b/src/fileutil.h @@ -50,11 +50,13 @@ class FileUtil : public QObject { static void openFolder(const QString &path); /** - * @brief setModificationTime sets file mofication and access time + * @brief setModificationTime sets file modification and access time * @param filename - relative or absolute file name * @param mtime - new file modification time */ static void setModificationTime(const QString &filename, const QDateTime &mtime); + static QString readFileText(const QString &filename); + static QStringList readFileLines(const QString &filename); }; #endif // FILEUTIL_H diff --git a/src/historyimp.cpp b/src/historyimp.cpp index bf3e5d3ac..309a99bfc 100644 --- a/src/historyimp.cpp +++ b/src/historyimp.cpp @@ -211,7 +211,7 @@ void HistoryImport::showDialog() { dlg = new QDialog(); dlg->setModal(true); - dlg->setWindowTitle(tr("Psi+ Import history")); + dlg->setWindowTitle(CAP(tr("Import history"))); QVBoxLayout *mainLayout = new QVBoxLayout(dlg); stackedWidget = new QStackedWidget(dlg); diff --git a/src/info.ui b/src/info.ui index 9d91e3bcd..ece23c8c3 100644 --- a/src/info.ui +++ b/src/info.ui @@ -54,46 +54,30 @@ 6 - - - - - 120 - 0 - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 0 - - - - - - + + - E-Mail: + Full Name: - - + + - Birthday: + Nickname: + + + + + + + + 120 + 0 + @@ -204,10 +188,17 @@ - - + + - Full Name: + Birthday: + + + + + + + true @@ -218,6 +209,9 @@ + + + @@ -225,29 +219,35 @@ - - - - Nickname: - - - - - + + - - - - true + + + + E-Mail: - - - + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 20 + 0 + + + + @@ -287,9 +287,6 @@ 6 - - - @@ -297,13 +294,6 @@ - - - - Position: - - - @@ -317,8 +307,15 @@ - - + + + + Position: + + + + + @@ -327,6 +324,9 @@ + + + @@ -384,28 +384,28 @@ 6 - - + + - Country: + Street: - - - - Postal Code: - - + + - - + + + + City: + + - - + + @@ -414,28 +414,28 @@ - - + + + + + - City: + Postal Code: - - + + - - + + - Street: + Country: - - - - - + + diff --git a/src/infodlg.cpp b/src/infodlg.cpp index 3a4ba54d2..454ed1fbd 100644 --- a/src/infodlg.cpp +++ b/src/infodlg.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -52,10 +53,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include @@ -473,9 +477,63 @@ void InfoWidget::setData(const VCard4::VCard &i) updatePhoto(); } + setupCountriesLookup(); setEdited(false); } +QStringList allCountryNames() +{ + QStringList names; + names.reserve(int(QLocale::LastCountry)); + for (int i = int(QLocale::AnyCountry) + 1; i <= int(QLocale::LastCountry); ++i) { + const auto country = static_cast(i); + QString code; + QString name; +#if QT_VERSION > QT_VERSION_CHECK(6, 2, 0) + code = QLocale::territoryToCode(country); + name = QLocale::territoryToString(country); +#else + name = QLocale::countryToString(country); +#endif + if (!name.isEmpty()) { + names.append(name + QLatin1Char('\t') + code); + } + } + names.sort(Qt::CaseInsensitive); + return names; +} + +void InfoWidget::setupCountriesLookup() +{ + QStringList countries = allCountryNames(); + QStandardItemModel *countriesModel = new QStandardItemModel(countries.size(), 2); + for (const auto &countryRow : countries) { + if (countryRow.isEmpty()) { + continue; + } + QString country = countryRow.section(QLatin1Char('\t'), 0, 0); + QString code = countryRow.section(QLatin1Char('\t'), 1, 1); + QList row = QList(); + row << new QStandardItem(country); + row << new QStandardItem(code); + countriesModel->appendRow(row); + } + + QTreeView *treeView = new QTreeView(this); + QCompleter *completer = new QCompleter(this); + completer->setModel(countriesModel); + completer->setPopup(treeView); + completer->setCaseSensitivity(Qt::CaseInsensitive); + + treeView->setRootIsDecorated(false); + treeView->header()->hide(); + treeView->header()->setStretchLastSection(false); + treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); + treeView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); + + this->m_ui.le_country->setCompleter(completer); +} + void InfoWidget::showEvent(QShowEvent *event) { QWidget::showEvent(event); diff --git a/src/infodlg.h b/src/infodlg.h index 7702796e8..34cb73906 100644 --- a/src/infodlg.h +++ b/src/infodlg.h @@ -58,6 +58,7 @@ public slots: void publish(); private slots: + void setupCountriesLookup(); void contactAvailable(const Jid &, const Resource &); void contactUnavailable(const Jid &, const Resource &); void contactUpdated(const Jid &); diff --git a/src/psiiconset.cpp b/src/psiiconset.cpp index a88828546..0c597237d 100644 --- a/src/psiiconset.cpp +++ b/src/psiiconset.cpp @@ -22,6 +22,7 @@ #include "anim.h" #include "applicationinfo.h" #include "common.h" +#include "fileutil.h" #include "psievent.h" #include "psioptions.h" #include "userlist.h" @@ -514,19 +515,14 @@ bool PsiIconset::loadClients() ClientIconMap cm; // start part, spec[spec2[spec3]] auto readClientsDesc = [&](const QString &filePath) { - QFile capsConv(filePath); + QStringList lines = FileUtil::readFileLines(filePath); + if (lines.isEmpty()) + return false; /* file format: , next line the same. */ - if (!capsConv.open(QIODevice::ReadOnly)) - return false; - - QTextStream stream(&capsConv); - - QString line; - while (!(line = stream.readLine()).isNull()) { - line = line.trimmed(); - QString iconName = line.section(QLatin1Char(' '), 0, 0); + for (const auto &line : lines) { + QString iconName = line.trimmed().section(QLatin1Char(' '), 0, 0); if (iconName.isEmpty() || !iconNames.contains(iconName)) { continue; } @@ -562,7 +558,7 @@ bool PsiIconset::loadClients() [](const auto &a, const auto &b) { return a.inside.size() > b.inside.size(); }); } - /* insert end boundry element to make search implementation simple */ + // insert end boundary element to make search implementation simple cm.insert(QLatin1String("~"), QList()); return true; }; diff --git a/src/psioptionseditor.cpp b/src/psioptionseditor.cpp index e43f07057..a8ca30835 100644 --- a/src/psioptionseditor.cpp +++ b/src/psioptionseditor.cpp @@ -93,7 +93,7 @@ OptionEditor::OptionEditor(bool new_, QString name_, QVariant value_) } } if (!ok) { - QMessageBox::critical(this, tr("Psi: Option Editor"), tr("Can't edit this type of setting, sorry."), + QMessageBox::critical(this, CAP(tr("Option Editor")), tr("Can't edit this type of setting, sorry."), QMessageBox::Close); deleteLater(); } @@ -106,7 +106,7 @@ void OptionEditor::finished() { QString option = le_option->text(); if (option.isEmpty() || option.endsWith(".") || option.contains("..") || !PsiOptions::isValidName(option)) { - QMessageBox::critical(this, tr("Psi: Option Editor"), + QMessageBox::critical(this, CAP(tr("Option Editor")), tr("Please enter option name.\n\n" "Option names may not be empty, end in '.' or contain '..'."), QMessageBox::Close); @@ -331,7 +331,7 @@ void PsiOptionsEditor::deleteit() confirm = tr("Really delete all options starting with %1.?"); } if (QMessageBox::Yes - == QMessageBox::warning(this, tr("Psi+: Option Editor"), confirm.arg(option), + == QMessageBox::warning(this, CAP(tr("Option Editor")), confirm.arg(option), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel)) { PsiOptions::instance()->removeOption(option, sub); } @@ -346,7 +346,7 @@ void PsiOptionsEditor::resetit() confirm = tr("Really reset all options starting with %1. to default value?"); } if (QMessageBox::Yes - == QMessageBox::warning(this, tr("Psi+: Option Editor"), confirm.arg(option), + == QMessageBox::warning(this, CAP(tr("Option Editor")), confirm.arg(option), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel)) { PsiOptions::instance()->resetOption(option); } diff --git a/src/showtextdlg.cpp b/src/showtextdlg.cpp index e34125600..5f17fb8ad 100644 --- a/src/showtextdlg.cpp +++ b/src/showtextdlg.cpp @@ -18,77 +18,34 @@ */ #include "showtextdlg.h" +#include "fileutil.h" -#include -#include -#include -#include -#include #include -#include // FIXME: combine to common init function ShowTextDlg::ShowTextDlg(const QString &fname, bool rich, QWidget *parent) : QDialog(parent) { - setAttribute(Qt::WA_DeleteOnClose); - QString text; - - QFile f(fname); - if (f.open(QIODevice::ReadOnly)) { - QTextStream t(&f); - while (!t.atEnd()) - text += t.readLine() + '\n'; - f.close(); - } - - QVBoxLayout *vb1 = new QVBoxLayout(this); - vb1->setContentsMargins(8, 8, 8, 8); - QTextEdit *te = new QTextEdit(this); - te->setReadOnly(true); - te->setAcceptRichText(rich); - te->setText(text); - if (rich) { - te->setTextInteractionFlags(Qt::TextBrowserInteraction); - } - - vb1->addWidget(te); - - QHBoxLayout *hb1 = new QHBoxLayout; - vb1->addLayout(hb1); - hb1->addStretch(1); - QPushButton *pb = new QPushButton(tr("&OK"), this); - connect(pb, SIGNAL(clicked()), SLOT(accept())); - hb1->addWidget(pb); - hb1->addStretch(1); - - resize(560, 384); + QString text = FileUtil::readFileText(fname); + renderDialog(text, rich); } ShowTextDlg::ShowTextDlg(const QString &text, bool nonfile, bool rich, QWidget *parent) : QDialog(parent) { Q_UNUSED(nonfile); + renderDialog(text, rich); +} + +void ShowTextDlg::renderDialog(const QString &text, bool rich) +{ setAttribute(Qt::WA_DeleteOnClose); + ui_.setupUi(this); - QVBoxLayout *vb1 = new QVBoxLayout(this); - vb1->setContentsMargins(8, 8, 8, 8); - QTextEdit *te = new QTextEdit(this); - te->setReadOnly(true); - te->setAcceptRichText(rich); - te->setText(text); + ui_.textEdit->setAcceptRichText(rich); + ui_.textEdit->setText(text); if (rich) { - te->setTextInteractionFlags(Qt::TextBrowserInteraction); + ui_.textEdit->setTextInteractionFlags(Qt::TextBrowserInteraction); } - vb1->addWidget(te); - - QHBoxLayout *hb1 = new QHBoxLayout; - vb1->addLayout(hb1); - hb1->addStretch(1); - QPushButton *pb = new QPushButton(tr("&OK"), this); - connect(pb, SIGNAL(clicked()), SLOT(accept())); - hb1->addWidget(pb); - hb1->addStretch(1); - resize(560, 384); } diff --git a/src/showtextdlg.h b/src/showtextdlg.h index 7c5d54855..0c13bccee 100644 --- a/src/showtextdlg.h +++ b/src/showtextdlg.h @@ -21,6 +21,7 @@ #define CS_SHOWTEXTDLG_H #include +#include "ui_showtextdlg.h" // TODO looks like its better to not use this class at all class ShowTextDlg : public QDialog { @@ -28,6 +29,9 @@ class ShowTextDlg : public QDialog { public: ShowTextDlg(const QString &fname, bool rich = false, QWidget *parent = nullptr); ShowTextDlg(const QString &text, bool nonfile, bool rich, QWidget *parent); +private: + Ui::ShowTextDlg ui_; + void renderDialog(const QString &text, bool rich); }; #endif // CS_SHOWTEXTDLG_H diff --git a/src/showtextdlg.ui b/src/showtextdlg.ui new file mode 100644 index 000000000..bee60cdd8 --- /dev/null +++ b/src/showtextdlg.ui @@ -0,0 +1,68 @@ + + + ShowTextDlg + + + + 0 + 0 + 560 + 384 + + + + + 8 + + + 8 + + + 8 + + + 8 + + + + + true + + + + + + + + + QDialogButtonBox::Ok + + + true + + + + + + + + + + + buttonBox + accepted() + ShowTextDlg + accept() + + + 279 + 352 + + + 279 + 191 + + + + + diff --git a/src/src.cmake b/src/src.cmake index 8b3a91154..47e97480a 100644 --- a/src/src.cmake +++ b/src/src.cmake @@ -63,6 +63,7 @@ list(APPEND FORMS rosteravatarframe.ui search.ui sendbuttontemplateseditor.ui + showtextdlg.ui voicecall.ui xmlconsole.ui )