X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fidentityeditwidget.cpp;h=9085ae9014ea1870c182a3d918e598005ab474e2;hp=e685b1efeba8c64374cff3705695ea33c90612c3;hb=4c5b4bf5355413e3f3df3704512ff350fa062961;hpb=694f9bfbf7f1af19108461c7e00d133e55082bce diff --git a/src/qtui/settingspages/identityeditwidget.cpp b/src/qtui/settingspages/identityeditwidget.cpp index e685b1ef..9085ae90 100644 --- a/src/qtui/settingspages/identityeditwidget.cpp +++ b/src/qtui/settingspages/identityeditwidget.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-2016 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,30 +15,37 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "identityeditwidget.h" -#include #include #include #include +#include +#include #include +#include + +#if QT_VERSION < 0x050000 +# include +#else +# include +#endif #include "client.h" -#include "iconloader.h" IdentityEditWidget::IdentityEditWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); - ui.addNick->setIcon(SmallIcon("list-add")); - ui.deleteNick->setIcon(SmallIcon("edit-delete")); - ui.renameNick->setIcon(SmallIcon("edit-rename")); - ui.nickUp->setIcon(SmallIcon("go-up")); - ui.nickDown->setIcon(SmallIcon("go-down")); + ui.addNick->setIcon(QIcon::fromTheme("list-add")); + ui.deleteNick->setIcon(QIcon::fromTheme("edit-delete")); + ui.renameNick->setIcon(QIcon::fromTheme("edit-rename")); + ui.nickUp->setIcon(QIcon::fromTheme("go-up")); + ui.nickDown->setIcon(QIcon::fromTheme("go-down")); // We need to know whenever the state of input widgets changes... connect(ui.realName, SIGNAL(textEdited(const QString &)), this, SIGNAL(widgetHasChanged())); @@ -78,6 +85,52 @@ IdentityEditWidget::IdentityEditWidget(QWidget *parent) ui.sslCertGroupBox->setAcceptDrops(true); ui.sslCertGroupBox->installEventFilter(this); #endif + + if (Client::coreFeatures() & Quassel::AwayFormatTimestamp) { + // Core allows formatting %%timestamp%% messages in away strings. Update tooltips. + QString strFormatTooltip; + QTextStream formatTooltip( &strFormatTooltip, QIODevice::WriteOnly ); + formatTooltip << ""; + + // Function to add a row to the tooltip table + auto addRow = [&](const QString& key, const QString& value, bool condition) { + if (condition) { + formatTooltip << "" + << key << "" << value << ""; + } + }; + + // Original tooltip goes here + formatTooltip << "

%1

"; + // New timestamp formatting guide here + formatTooltip << "

" << tr("You can add date/time to this message " + "using the syntax: " + "
%%<format>%%, where " + "<format> is:") << "

"; + formatTooltip << ""; + addRow("hh", tr("the hour"), true); + addRow("mm", tr("the minutes"), true); + addRow("ss", tr("seconds"), true); + addRow("AP", tr("AM/PM"), true); + addRow("dd", tr("day"), true); + addRow("MM", tr("month"), true); +#if QT_VERSION > 0x050000 + // Alas, this was only added in Qt 5. We don't know what version the core has, just hope + // for the best (Qt 4 will soon be dropped). + addRow("t", tr("current timezone"), true); +#endif + formatTooltip << "
"; + formatTooltip << "

" << tr("Example: Away since %%hh:mm%% on %%dd.MM%%.") << "

"; + formatTooltip << "

" << tr("%%%% without anything inside represents %%. Other format " + "codes are available.") << "

"; + formatTooltip << "
"; + + // Split up the message to allow re-using translations: + // [Original tool-tip] [Timestamp format message] + ui.awayReason->setToolTip(strFormatTooltip.arg(ui.awayReason->toolTip())); + ui.detachAwayEnabled->setToolTip(strFormatTooltip.arg(ui.detachAwayEnabled->toolTip())); + } // else: Do nothing, leave the original translated string } @@ -134,6 +187,7 @@ void IdentityEditWidget::displayIdentity(CertIdentity *id, CertIdentity *saveId) void IdentityEditWidget::saveToIdentity(CertIdentity *id) { + QRegExp linebreaks = QRegExp("[\\r\\n]"); id->setRealName(ui.realName->text()); QStringList nicks; for (int i = 0; i < ui.nicknameList->count(); i++) { @@ -142,19 +196,19 @@ void IdentityEditWidget::saveToIdentity(CertIdentity *id) id->setNicks(nicks); id->setAwayNick(ui.awayNick->text()); id->setAwayNickEnabled(true); - id->setAwayReason(ui.awayReason->text()); + id->setAwayReason(ui.awayReason->text().remove(linebreaks)); id->setAwayReasonEnabled(true); id->setAutoAwayEnabled(ui.autoAwayEnabled->isChecked()); id->setAutoAwayTime(ui.autoAwayTime->value()); - id->setAutoAwayReason(ui.autoAwayReason->text()); + id->setAutoAwayReason(ui.autoAwayReason->text().remove(linebreaks)); id->setAutoAwayReasonEnabled(ui.autoAwayReasonEnabled->isChecked()); id->setDetachAwayEnabled(ui.detachAwayEnabled->isChecked()); - id->setDetachAwayReason(ui.detachAwayReason->text()); + id->setDetachAwayReason(ui.detachAwayReason->text().remove(linebreaks)); id->setDetachAwayReasonEnabled(true); id->setIdent(ui.ident->text()); - id->setKickReason(ui.kickReason->text()); - id->setPartReason(ui.partReason->text()); - id->setQuitReason(ui.quitReason->text()); + id->setKickReason(ui.kickReason->text().remove(linebreaks)); + id->setPartReason(ui.partReason->text().remove(linebreaks)); + id->setQuitReason(ui.quitReason->text().remove(linebreaks)); #ifdef HAVE_SSL id->setSslKey(QSslKey(ui.keyTypeLabel->property("sslKey").toByteArray(), (QSsl::KeyAlgorithm)(ui.keyTypeLabel->property("sslKeyType").toInt()))); id->setSslCert(QSslCertificate(ui.certOrgLabel->property("sslCert").toByteArray())); @@ -298,7 +352,7 @@ void IdentityEditWidget::sslDropEvent(QDropEvent *event, bool isCert) if (isCert) { QSslCertificate cert = certByFilename(filename); - if (cert.isValid()) + if (!cert.isNull()) showCertState(cert); } else { @@ -316,7 +370,12 @@ void IdentityEditWidget::on_clearOrLoadKeyButton_clicked() QSslKey key; if (ui.keyTypeLabel->property("sslKey").toByteArray().isEmpty()) - key = keyByFilename(QFileDialog::getOpenFileName(this, tr("Load a Key"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation))); + key = keyByFilename(QFileDialog::getOpenFileName(this, tr("Load a Key"), +#if QT_VERSION < 0x050000 + QDesktopServices::storageLocation(QDesktopServices::HomeLocation))); +#else + QStandardPaths::writableLocation(QStandardPaths::HomeLocation))); +#endif showKeyState(key); emit widgetHasChanged(); @@ -339,6 +398,7 @@ QSslKey IdentityEditWidget::keyByFilename(const QString &filename) goto returnKey; } } + QMessageBox::information(this, tr("Failed to read key"), tr("Failed to read the key file. It is either incompatible or invalid. Note that the key file must not have a passphrase.")); returnKey: return key; } @@ -373,8 +433,12 @@ void IdentityEditWidget::on_clearOrLoadCertButton_clicked() QSslCertificate cert; if (ui.certOrgLabel->property("sslCert").toByteArray().isEmpty()) - cert = certByFilename(QFileDialog::getOpenFileName(this, tr("Load a Certificate"), QDesktopServices::storageLocation(QDesktopServices::HomeLocation))); - + cert = certByFilename(QFileDialog::getOpenFileName(this, tr("Load a Certificate"), +#if QT_VERSION < 0x050000 + QDesktopServices::storageLocation(QDesktopServices::HomeLocation))); +#else + QStandardPaths::writableLocation(QStandardPaths::HomeLocation))); +#endif showCertState(cert); emit widgetHasChanged(); } @@ -390,7 +454,7 @@ QSslCertificate IdentityEditWidget::certByFilename(const QString &filename) for (int i = 0; i < 2; i++) { cert = QSslCertificate(certRaw, (QSsl::EncodingFormat)i); - if (cert.isValid()) + if (!cert.isNull()) break; } return cert; @@ -399,14 +463,19 @@ QSslCertificate IdentityEditWidget::certByFilename(const QString &filename) void IdentityEditWidget::showCertState(const QSslCertificate &cert) { - if (!cert.isValid()) { + if (cert.isNull()) { ui.certOrgLabel->setText(tr("No Certificate loaded")); ui.certCNameLabel->setText(tr("No Certificate loaded")); ui.clearOrLoadCertButton->setText(tr("Load")); } else { +#if QT_VERSION < 0x050000 ui.certOrgLabel->setText(cert.subjectInfo(QSslCertificate::Organization)); ui.certCNameLabel->setText(cert.subjectInfo(QSslCertificate::CommonName)); +#else + ui.certOrgLabel->setText(cert.subjectInfo(QSslCertificate::Organization).join(", ")); + ui.certCNameLabel->setText(cert.subjectInfo(QSslCertificate::CommonName).join(", ")); +#endif ui.clearOrLoadCertButton->setText(tr("Clear")); } ui.certOrgLabel->setProperty("sslCert", cert.toPem());