-: QObject(parent),
- _channelJoinedIcon(SmallIcon("irc-channel-active")),
- _channelPartedIcon(SmallIcon("irc-channel-inactive")),
- _userOfflineIcon(SmallIcon("im-user-offline")),
- _userOnlineIcon(SmallIcon("im-user")),
- _userAwayIcon(SmallIcon("im-user-away")),
- _categoryOpIcon(SmallIcon("irc-operator")),
- _categoryVoiceIcon(SmallIcon("irc-voice")),
- _opIconLimit(UserCategoryItem::categoryFromModes("o")),
- _voiceIconLimit(UserCategoryItem::categoryFromModes("v"))
-{
- // register FormatList if that hasn't happened yet
- // FIXME I don't think this actually avoids double registration... then again... does it hurt?
- if(QVariant::nameToType("UiStyle::FormatList") == QVariant::Invalid) {
- qRegisterMetaType<FormatList>("UiStyle::FormatList");
- qRegisterMetaTypeStreamOperators<FormatList>("UiStyle::FormatList");
- Q_ASSERT(QVariant::nameToType("UiStyle::FormatList") != QVariant::Invalid);
- }
-
- _uiStylePalette = QVector<QBrush>(NumRoles, QBrush());
-
- // Now initialize the mapping between FormatCodes and FormatTypes...
- _formatCodes["%O"] = Base;
- _formatCodes["%B"] = Bold;
- _formatCodes["%S"] = Italic;
- _formatCodes["%U"] = Underline;
- _formatCodes["%R"] = Reverse;
-
- _formatCodes["%DN"] = Nick;
- _formatCodes["%DH"] = Hostmask;
- _formatCodes["%DC"] = ChannelName;
- _formatCodes["%DM"] = ModeFlags;
- _formatCodes["%DU"] = Url;
-
- setTimestampFormatString("[hh:mm:ss]");
-
- // BufferView / NickView settings
- UiStyleSettings s;
- _showBufferViewIcons = _showNickViewIcons = s.value("ShowItemViewIcons", true).toBool();
- s.notify("ShowItemViewIcons", this, SLOT(showItemViewIconsChanged(QVariant)));
-
- _allowMircColors = s.value("AllowMircColors", true).toBool();
- s.notify("AllowMircColors", this, SLOT(allowMircColorsChanged(QVariant)));
-
- loadStyleSheet();
-}
-
-UiStyle::~UiStyle() {
- qDeleteAll(_metricsCache);
-}
-
-void UiStyle::reload() {
- loadStyleSheet();
-}
-
-void UiStyle::loadStyleSheet() {
- qDeleteAll(_metricsCache);
- _metricsCache.clear();
- _formatCache.clear();
- _formats.clear();
-
- UiStyleSettings s;
-
- QString styleSheet;
- styleSheet += loadStyleSheet("file:///" + Quassel::findDataFilePath("stylesheets/default.qss"));
- styleSheet += loadStyleSheet("file:///" + Quassel::configDirPath() + "settings.qss");
- if(s.value("UseCustomStyleSheet", false).toBool())
- styleSheet += loadStyleSheet("file:///" + s.value("CustomStyleSheetPath").toString(), true);
- styleSheet += loadStyleSheet("file:///" + Quassel::optionValue("qss"), true);
-
- if(!styleSheet.isEmpty()) {
- QssParser parser;
- parser.processStyleSheet(styleSheet);
- QApplication::setPalette(parser.palette());
-
- _uiStylePalette = parser.uiStylePalette();
- _formats = parser.formats();
- _listItemFormats = parser.listItemFormats();
-
- styleSheet = styleSheet.trimmed();
- if(!styleSheet.isEmpty())
- qApp->setStyleSheet(styleSheet); // pass the remaining sections to the application
- }
-
- emit changed();
-}
-
-QString UiStyle::loadStyleSheet(const QString &styleSheet, bool shouldExist) {
- QString ss = styleSheet;
- if(ss.startsWith("file:///")) {
- ss.remove(0, 8);
- if(ss.isEmpty())
- return QString();
-
- QFile file(ss);
- if(file.open(QFile::ReadOnly)) {
- QTextStream stream(&file);
- ss = stream.readAll();
- file.close();
+ : QObject(parent),
+ _channelJoinedIcon(QIcon::fromTheme("irc-channel-joined", QIcon(":/icons/irc-channel-joined.png"))),
+ _channelPartedIcon(QIcon::fromTheme("irc-channel-parted", QIcon(":/icons/irc-channel-parted.png"))),
+ _userOfflineIcon(QIcon::fromTheme("im-user-offline", QIcon::fromTheme("user-offline", QIcon(":/icons/im-user-offline.png")))),
+ _userOnlineIcon(QIcon::fromTheme("im-user", QIcon::fromTheme("user-available", QIcon(":/icons/im-user.png")))), // im-user-* are non-standard oxygen extensions
+ _userAwayIcon(QIcon::fromTheme("im-user-away", QIcon::fromTheme("user-away", QIcon(":/icons/im-user-away.png")))),
+ _categoryOpIcon(QIcon::fromTheme("irc-operator")),
+ _categoryVoiceIcon(QIcon::fromTheme("irc-voice")),
+ _opIconLimit(UserCategoryItem::categoryFromModes("o")),
+ _voiceIconLimit(UserCategoryItem::categoryFromModes("v"))
+{
+ // register FormatList if that hasn't happened yet
+ // FIXME I don't think this actually avoids double registration... then again... does it hurt?
+ if (QVariant::nameToType("UiStyle::FormatList") == QVariant::Invalid) {
+ qRegisterMetaType<FormatList>("UiStyle::FormatList");
+ qRegisterMetaTypeStreamOperators<FormatList>("UiStyle::FormatList");
+ Q_ASSERT(QVariant::nameToType("UiStyle::FormatList") != QVariant::Invalid);
+ }
+
+ _uiStylePalette = QVector<QBrush>(NumRoles, QBrush());
+
+ // Now initialize the mapping between FormatCodes and FormatTypes...
+ _formatCodes["%O"] = Base;
+ _formatCodes["%B"] = Bold;
+ _formatCodes["%S"] = Italic;
+ _formatCodes["%U"] = Underline;
+ _formatCodes["%R"] = Reverse;
+
+ _formatCodes["%DN"] = Nick;
+ _formatCodes["%DH"] = Hostmask;
+ _formatCodes["%DC"] = ChannelName;
+ _formatCodes["%DM"] = ModeFlags;
+ _formatCodes["%DU"] = Url;
+
+ // Initialize fallback defaults
+ // NOTE: If you change this, update qtui/chatviewsettings.h, too. More explanations available
+ // in there.
+ setUseCustomTimestampFormat(false);
+ setTimestampFormatString(" hh:mm:ss");
+ enableSenderPrefixes(false);
+ enableSenderBrackets(true);
+
+ // BufferView / NickView settings
+ UiStyleSettings s;
+ _showBufferViewIcons = _showNickViewIcons = s.value("ShowItemViewIcons", true).toBool();
+ s.notify("ShowItemViewIcons", this, SLOT(showItemViewIconsChanged(QVariant)));
+
+ _allowMircColors = s.value("AllowMircColors", true).toBool();
+ s.notify("AllowMircColors", this, SLOT(allowMircColorsChanged(QVariant)));
+
+ loadStyleSheet();
+}
+
+
+UiStyle::~UiStyle()
+{
+ qDeleteAll(_metricsCache);
+}
+
+
+void UiStyle::reload()
+{
+ loadStyleSheet();
+}
+
+
+void UiStyle::loadStyleSheet()
+{
+ qDeleteAll(_metricsCache);
+ _metricsCache.clear();
+ _formatCache.clear();
+ _formats.clear();
+
+ UiStyleSettings s;
+
+ QString styleSheet;
+ styleSheet += loadStyleSheet("file:///" + Quassel::findDataFilePath("stylesheets/default.qss"));
+ styleSheet += loadStyleSheet("file:///" + Quassel::configDirPath() + "settings.qss");
+ if (s.value("UseCustomStyleSheet", false).toBool()) {
+ QString customSheetPath(s.value("CustomStyleSheetPath").toString());
+ QString customSheet = loadStyleSheet("file:///" + customSheetPath, true);
+ if (customSheet.isEmpty()) {
+ // MIGRATION: changed default install path for data from /usr/share/apps to /usr/share
+ if (customSheetPath.startsWith("/usr/share/apps/quassel")) {
+ customSheetPath.replace(QRegExp("^/usr/share/apps"), "/usr/share");
+ customSheet = loadStyleSheet("file:///" + customSheetPath, true);
+ if (!customSheet.isEmpty()) {
+ s.setValue("CustomStyleSheetPath", customSheetPath);
+ qDebug() << "Custom stylesheet path migrated to" << customSheetPath;
+ }
+ }
+ }
+ styleSheet += customSheet;
+ }
+ styleSheet += loadStyleSheet("file:///" + Quassel::optionValue("qss"), true);
+
+ if (!styleSheet.isEmpty()) {
+ QssParser parser;
+ parser.processStyleSheet(styleSheet);
+ QApplication::setPalette(parser.palette());
+
+ _uiStylePalette = parser.uiStylePalette();
+ _formats = parser.formats();
+ _listItemFormats = parser.listItemFormats();
+
+ styleSheet = styleSheet.trimmed();
+ if (!styleSheet.isEmpty())
+ qApp->setStyleSheet(styleSheet); // pass the remaining sections to the application
+ }
+
+ emit changed();
+}
+
+
+QString UiStyle::loadStyleSheet(const QString &styleSheet, bool shouldExist)
+{
+ QString ss = styleSheet;
+ if (ss.startsWith("file:///")) {
+ ss.remove(0, 8);
+ if (ss.isEmpty())
+ return QString();
+
+ QFile file(ss);
+ if (file.open(QFile::ReadOnly)) {
+ QTextStream stream(&file);
+ ss = stream.readAll();
+ file.close();
+ }
+ else {
+ if (shouldExist)
+ qWarning() << "Could not open stylesheet file:" << file.fileName();
+ return QString();
+ }
+ }
+ return ss;
+}
+
+
+void UiStyle::updateSystemTimestampFormat()
+{
+ // Does the system locale use AM/PM designators? For example:
+ // AM/PM: h:mm AP
+ // AM/PM: hh:mm a
+ // 24-hour: h:mm
+ // 24-hour: hh:mm ADD things
+ // For timestamp format, see https://doc.qt.io/qt-5/qdatetime.html#toString
+ // This won't update if the system locale is changed while Quassel is running. If need be,
+ // Quassel could hook into notifications of changing system locale to update this.
+ //
+ // Match any AP or A designation if on a word boundary, including underscores.
+ // .*(\b|_)(A|AP)(\b|_).*
+ // .* Match any number of characters
+ // \b Match a word boundary, i.e. "AAA.BBB", "." is matched
+ // _ Match the literal character '_' (not considered a word boundary)
+ // (X|Y) Match either X or Y, exactly
+ //
+ // Note that '\' must be escaped as '\\'
+ // QRegExp does not support (?> ...), so it's replaced with standard matching, (...)
+ // Helpful interactive website for debugging and explaining: https://regex101.com/
+ const QRegExp regExpMatchAMPM(".*(\\b|_)(A|AP)(\\b|_).*", Qt::CaseInsensitive);
+
+ if (regExpMatchAMPM.exactMatch(QLocale::system().timeFormat(QLocale::ShortFormat))) {
+ // AM/PM style used
+ _systemTimestampFormatString = " h:mm:ss ap";