Esempio n. 1
0
        public void LoadTheme(string themeName, string variantName)
        {
            if (this.ChatHandler == null) {
                throw new InvalidOperationException("Set ChatHandler first");
            }

            string themeDirectory = System.IO.Path.Combine(ThemesDirectory, themeName) + ".AdiumMessageStyle";
            if (!Directory.Exists(themeDirectory)) {
                throw new DirectoryNotFoundException(themeDirectory);
            }

            m_StylePath = Util.JoinPath(themeDirectory, "Contents", "Resources");

            string plistPath = Util.JoinPath(themeDirectory, "Contents", "Info.plist");

            // XXX: Add additional checks for other required files.
            if (!File.Exists(plistPath)) {
                throw new Exception("Missing required theme file: Info.plist");
            }

            m_StyleInfo = new PList(plistPath);

            // Default Behavior
            m_AllowsCustomBackground = true;
            m_AllowsUserIcons = true;

            m_StyleVersion = m_StyleInfo.GetInt("MessageViewVersion");

            // Pre-fetch our templates
            LoadTemplates();

            // Style flags
            m_AllowsCustomBackground = !m_StyleInfo.Get<bool>("DisableCustomBackground");
            m_TransparentDefaultBackground = m_StyleInfo.Get<bool>("DefaultBackgroundIsTransparent");
            if (m_TransparentDefaultBackground) {
                // FIXME:
                Console.WriteLine("Transparent background not supported");
            }

            m_CombineConsecutive = !m_StyleInfo.Get<bool>("DisableCombineConsecutive");

            if (m_StyleInfo.ContainsKey("ShowsUserIcons")) {
                m_AllowsUserIcons = m_StyleInfo.Get<bool>("ShowsUserIcons");
            }

            // User icon masking
            var maskName = m_StyleInfo.Get<string>("ImageMask");
            if (!String.IsNullOrEmpty(maskName)) {
                // FIXME:
                Console.WriteLine("ImageMask not supported");
            }

            m_AllowsColors = m_StyleInfo.Get<bool>("AllowTextColors");
            if (!m_AllowsColors) {
                Console.WriteLine("AllowTextColors not supported");
            }

            // FIXME: Need to selectively show certain actions depending on what's under the cursor.
            //this.AddAction(this.PageAction(QWebPage.WebAction.OpenLink));
            //this.AddAction(this.PageAction(QWebPage.WebAction.CopyLinkToClipboard));
            //this.AddAction(this.PageAction(QWebPage.WebAction.CopyImageToClipboard));
            //this.AddSeparator();
            QAction copyAction = this.PageAction(QWebPage.WebAction.Copy);
            copyAction.SetShortcuts(QKeySequence.StandardKey.Copy);
            this.AddAction(copyAction);
            this.AddAction(this.PageAction(QWebPage.WebAction.InspectElement));

            // Create the base template
            string baseUri = "file://" + m_StylePath + "/";
            string mainCssPath = "main.css";
            string variantCssPath = PathForVariant(variantName);
            var formattedBaseTemplate = FormatBaseTemplate(baseUri, mainCssPath, variantCssPath);
            base.Page().MainFrame().SetHtml(formattedBaseTemplate, themeDirectory);

            QObject.Connect(this.Page().MainFrame(), Qt.SIGNAL("javaScriptWindowObjectCleared()"), HandleJavaScriptWindowObjectCleared);

            if (ConversationWidget.ThemesDirectory == null) {
                throw new Exception("Set ThemesDirectory first");
            }

            this.ContextMenuPolicy = ContextMenuPolicy.ActionsContextMenu;

            this.Page().linkDelegationPolicy = QWebPage.LinkDelegationPolicy.DelegateAllLinks;
            QObject.Connect<QUrl>(this, Qt.SIGNAL("linkClicked(QUrl)"), HandleLinkClicked);

            m_ThemeLoaded = true;

            HandleJavaScriptWindowObjectCleared();
        }
Esempio n. 2
0
        public void LoadTheme(string themeName, string variantName)
        {
            if (this.ChatHandler == null)
            {
                throw new InvalidOperationException("Set ChatHandler first");
            }

            string themeDirectory = System.IO.Path.Combine(ThemesDirectory, themeName) + ".AdiumMessageStyle";

            if (!Directory.Exists(themeDirectory))
            {
                throw new DirectoryNotFoundException(themeDirectory);
            }

            m_StylePath = Util.JoinPath(themeDirectory, "Contents", "Resources");

            string plistPath = Util.JoinPath(themeDirectory, "Contents", "Info.plist");

            // XXX: Add additional checks for other required files.
            if (!File.Exists(plistPath))
            {
                throw new Exception("Missing required theme file: Info.plist");
            }

            m_StyleInfo = new PList(plistPath);

            // Default Behavior
            m_AllowsCustomBackground = true;
            m_AllowsUserIcons        = true;

            m_StyleVersion = m_StyleInfo.GetInt("MessageViewVersion");

            // Pre-fetch our templates
            LoadTemplates();

            // Style flags
            m_AllowsCustomBackground       = !m_StyleInfo.Get <bool>("DisableCustomBackground");
            m_TransparentDefaultBackground = m_StyleInfo.Get <bool>("DefaultBackgroundIsTransparent");
            if (m_TransparentDefaultBackground)
            {
                // FIXME:
                Console.WriteLine("Transparent background not supported");
            }

            m_CombineConsecutive = !m_StyleInfo.Get <bool>("DisableCombineConsecutive");

            if (m_StyleInfo.ContainsKey("ShowsUserIcons"))
            {
                m_AllowsUserIcons = m_StyleInfo.Get <bool>("ShowsUserIcons");
            }

            // User icon masking
            var maskName = m_StyleInfo.Get <string>("ImageMask");

            if (!String.IsNullOrEmpty(maskName))
            {
                // FIXME:
                Console.WriteLine("ImageMask not supported");
            }

            m_AllowsColors = m_StyleInfo.Get <bool>("AllowTextColors");
            if (!m_AllowsColors)
            {
                Console.WriteLine("AllowTextColors not supported");
            }

            // FIXME: Need to selectively show certain actions depending on what's under the cursor.
            //this.AddAction(this.PageAction(QWebPage.WebAction.OpenLink));
            //this.AddAction(this.PageAction(QWebPage.WebAction.CopyLinkToClipboard));
            //this.AddAction(this.PageAction(QWebPage.WebAction.CopyImageToClipboard));
            //this.AddSeparator();
            QAction copyAction = this.PageAction(QWebPage.WebAction.Copy);

            copyAction.SetShortcuts(QKeySequence.StandardKey.Copy);
            this.AddAction(copyAction);
            this.AddAction(this.PageAction(QWebPage.WebAction.InspectElement));

            // Create the base template
            string baseUri               = "file://" + m_StylePath + "/";
            string mainCssPath           = "main.css";
            string variantCssPath        = PathForVariant(variantName);
            var    formattedBaseTemplate = FormatBaseTemplate(baseUri, mainCssPath, variantCssPath);

            base.Page().MainFrame().SetHtml(formattedBaseTemplate, themeDirectory);

            QObject.Connect(this.Page().MainFrame(), Qt.SIGNAL("javaScriptWindowObjectCleared()"), HandleJavaScriptWindowObjectCleared);

            if (ConversationWidget.ThemesDirectory == null)
            {
                throw new Exception("Set ThemesDirectory first");
            }

            this.ContextMenuPolicy = ContextMenuPolicy.ActionsContextMenu;

            this.Page().linkDelegationPolicy = QWebPage.LinkDelegationPolicy.DelegateAllLinks;
            QObject.Connect <QUrl>(this, Qt.SIGNAL("linkClicked(QUrl)"), HandleLinkClicked);

            m_ThemeLoaded = true;

            HandleJavaScriptWindowObjectCleared();
        }