SimpleMessageStyle::SimpleMessageStyle(const QString &AStylePath, QNetworkAccessManager *ANetworkAccessManager, QObject *AParent) : QObject(AParent) { if (FSharedPath.isEmpty()) { if (QDir::isRelativePath(SHARED_STYLE_PATH)) FSharedPath = qApp->applicationDirPath()+"/"SHARED_STYLE_PATH; else FSharedPath = SHARED_STYLE_PATH; } FStylePath = AStylePath; FInfo = styleInfo(AStylePath); FVariants = styleVariants(AStylePath); FNetworkAccessManager=ANetworkAccessManager; initStyleSettings(); loadTemplates(); loadSenderColors(); FScrollTimer.setSingleShot(true); FScrollTimer.setInterval(SCROLL_TIMEOUT); connect(&FScrollTimer,SIGNAL(timeout()),SLOT(onScrollAfterResize())); connect(AParent,SIGNAL(styleWidgetAdded(IMessageStyle *, QWidget *)),SLOT(onStyleWidgetAdded(IMessageStyle *, QWidget *))); }
IMessageStyleOptions SimpleMessageStyleEngine::styleOptions(const OptionsNode &AEngineNode, const QString &AStyleId) const { IMessageStyleOptions options; if (AStyleId.isEmpty() || FStylePaths.contains(AStyleId)) { QString styleId = AStyleId.isEmpty() ? AEngineNode.value("style-id").toString() : AStyleId; // Select default style if (!FStylePaths.isEmpty() && !FStylePaths.contains(styleId)) { int mtype = AEngineNode.parentNSpaces().value(1).toInt(); switch (mtype) { case Message::Normal: case Message::Headline: case Message::Error: styleId = "Message Style"; AEngineNode.node("style",styleId).setValue(QString("Default"),"variant"); break; default: styleId = "Chat Style"; AEngineNode.node("style",styleId).setValue(QString("Default"),"variant"); } styleId = !FStylePaths.contains(styleId) ? FStylePaths.keys().first() : styleId; } if (FStylePaths.contains(styleId)) { options.engineId = engineId(); options.styleId = styleId; OptionsNode styleNode = AEngineNode.node("style",styleId); options.extended.insert(MSO_VARIANT,styleNode.value("variant")); options.extended.insert(MSO_FONT_FAMILY,styleNode.value("font-family")); options.extended.insert(MSO_FONT_SIZE,styleNode.value("font-size")); options.extended.insert(MSO_SELF_COLOR,styleNode.value("self-color")); options.extended.insert(MSO_CONTACT_COLOR,styleNode.value("contact-color")); options.extended.insert(MSO_BG_COLOR,styleNode.value("bg-color")); options.extended.insert(MSO_BG_IMAGE_FILE,styleNode.value("bg-image-file")); QList<QString> variants = styleVariants(styleId); QMap<QString,QVariant> info = styleInfo(styleId); if (!variants.contains(options.extended.value(MSO_VARIANT).toString())) options.extended.insert(MSO_VARIANT,info.value(MSIV_DEFAULT_VARIANT, variants.value(0))); if (info.value(MSIV_DISABLE_CUSTOM_BACKGROUND,false).toBool()) { options.extended.remove(MSO_BG_IMAGE_FILE); options.extended.insert(MSO_BG_COLOR,info.value(MSIV_DEFAULT_BACKGROUND_COLOR)); } else if (options.extended.value(MSO_BG_COLOR).toString().isEmpty()) { options.extended.insert(MSO_BG_COLOR,info.value(MSIV_DEFAULT_BACKGROUND_COLOR)); } if (options.extended.value(MSO_FONT_FAMILY).toString().isEmpty()) options.extended.insert(MSO_FONT_FAMILY,info.value(MSIV_DEFAULT_FONT_FAMILY)); if (options.extended.value(MSO_FONT_SIZE).toInt() == 0) options.extended.insert(MSO_FONT_SIZE,info.value(MSIV_DEFAULT_FONT_SIZE)); if (options.extended.value(MSO_SELF_COLOR).toString().isEmpty()) options.extended.insert(MSO_SELF_COLOR,info.value(MSIV_DEFAULT_SELF_COLOR,QColor(Qt::red).name())); if (options.extended.value(MSO_CONTACT_COLOR).toString().isEmpty()) options.extended.insert(MSO_CONTACT_COLOR,info.value(MSIV_DEFAULT_CONTACT_COLOR,QColor(Qt::blue).name())); } else { REPORT_ERROR("Failed to find any suitable simple message style"); } } else { REPORT_ERROR(QString("Failed to get adium style options for style=%1: Style not found").arg(AStyleId)); } return options; }