Ejemplo n.º 1
0
        private void HandleColorsDrawItem(object sender, DrawItemEventArgs e)
        {
            Debug.Assert(ReferenceEquals(sender, m_cbColors));

            ComboBox cb = ((ComboBox)sender);

            if (0 > e.Index || e.Index > cb.Items.Count)
            {
                return;
            }

            // Draw a combo box item using the color as a background.
            Graphics  g    = e.Graphics;
            Rectangle rect = e.Bounds;

            // Get the color proxy object.
            GoogleColor item = (GoogleColor)cb.Items[e.Index];

            // Background fill color painting.
            Brush brush = new SolidBrush(item.Color);

            g.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);

            // Foreground is the color name in black.
            g.DrawString(item.ToString(), cb.Font,
                         Brushes.Black, rect.X, rect.Top);
        }
Ejemplo n.º 2
0
        private void HandleColorsSelectedIndexChanged(object sender,
                                                      EventArgs e)
        {
            GoogleColor item = m_cbColors.Items
                               .Cast <GoogleColor>()
                               .ElementAt(m_cbColors.SelectedIndex);

            m_cbColors.BackColor         = item.Color;
            m_data.DefaultAppFolderColor = item == m_nullColor ? null : item;
        }
Ejemplo n.º 3
0
        public static void InitAppConfig(IPluginHost host)
        {
            PluginConfig update = new PluginConfig();
            string       cmds   = host.GetConfig(GdsDefs.ConfigEnabledCmds,
                                                 ((int)SyncCommands.All).ToString(
                                                     NumberFormatInfo.InvariantInfo));
            int cmdsAsInt;

            if (!int.TryParse(cmds, NumberStyles.Integer,
                              NumberFormatInfo.InvariantInfo, out cmdsAsInt))
            {
                cmdsAsInt = (int)SyncCommands.All;
            }
            update.EnabledCommands = (SyncCommands)cmdsAsInt;

            string syncOption = host.GetConfig(GdsDefs.ConfigAutoSync,
                                               AutoSyncMode.DISABLED.ToString());
            AutoSyncMode mode;

            if (!Enum.TryParse(syncOption, out mode))
            {
                // Support obsolete Sync on Save confg.
                if (host.GetConfig(GdsDefs.ConfigAutoSync, false))
                {
                    mode = AutoSyncMode.SAVE;
                }
                else
                {
                    mode = AutoSyncMode.DISABLED;
                }
            }
            update.AutoSync = mode;

            update.Folder = host.GetConfig(GdsDefs.ConfigDefaultAppFolder,
                                           string.Empty);
            string encodedColor = host.GetConfig(
                GdsDefs.ConfigDefaultAppFolderColor);

            update.FolderColor = !string.IsNullOrEmpty(encodedColor) ?
                                 GoogleColor.DeserializeFromString(encodedColor) : null;

            update.DriveScope = host.GetConfig(GdsDefs.ConfigDriveScope,
                                               DriveService.Scope.Drive);

            // Default is no OAuth 2.0 credentials.
            update.ClientId = host.GetConfig(GdsDefs.ConfigDefaultClientId,
                                             string.Empty);
            string secretVal = host.GetConfig(GdsDefs.ConfigDefaultClientSecret,
                                              string.Empty);

            update.ClientSecret = new ProtectedString(true, secretVal);

            update.m_isDirty = false;
            Default          = update;
        }
Ejemplo n.º 4
0
 PluginConfig()
 {
     m_autoSync            = AutoSyncMode.DISABLED;
     m_enabledCmds         = SyncCommands.All;
     m_defaultFolder       = null;
     m_defaultFolderColor  = null;
     m_defaultDriveScope   = null;
     m_defaultClientId     = string.Empty;
     m_defaultClientSecret = GdsDefs.PsEmptyEx;
     m_isDirty             = false;
 }
Ejemplo n.º 5
0
 public void UpdateConfig(IPluginHost host)
 {
     if (!m_isDirty)
     {
         return;
     }
     host.SetConfig(GdsDefs.ConfigEnabledCmds,
                    ((int)m_enabledCmds).ToString(NumberFormatInfo.InvariantInfo));
     host.SetConfig(GdsDefs.ConfigAutoSync, m_autoSync.ToString());
     host.SetConfig(GdsDefs.ConfigDefaultAppFolder, m_defaultFolder);
     host.SetConfig(GdsDefs.ConfigDefaultAppFolderColor,
                    m_defaultFolderColor == null ? null :
                    GoogleColor.SerializeToString(m_defaultFolderColor));
     host.SetConfig(GdsDefs.ConfigDriveScope, m_defaultDriveScope);
     host.SetConfig(GdsDefs.ConfigDefaultClientId, m_defaultClientId);
     host.SetConfig(GdsDefs.ConfigDefaultClientSecret,
                    m_defaultClientSecret == null ? string.Empty :
                    m_defaultClientSecret.ReadString());
 }
Ejemplo n.º 6
0
        public static string SerializeToString(GoogleColor c)
        {
            if (c == null)
            {
                return(null);
            }

            IFormatter formatter = new BinaryFormatter()
            {
                Binder = new GoogleColor.Binder(),
            };
            MemoryStream ms = new MemoryStream();

            using (ms)
            {
                formatter.Serialize(ms, c);
                return(MemUtil.ByteArrayToHexString(ms.ToArray()));
            }
        }
Ejemplo n.º 7
0
        public ConfigurationForm(ConfigurationFormData data)
        {
            InitializeComponent();

            Text                = GdsDefs.ProductName;
            DatabaseFilePath    = string.Empty;
            m_lblAboutVer.Text  = GdsDefs.Version;
            m_lblAboutProd.Text = GdsDefs.ProductName;

            // Localize the form
            Control[] textCx = new Control[]
            {
                m_lnkGoogle,
                m_lnkHelp,
                m_lnkHome,
                m_lnkGoogle2,
                m_lnkHelp2,
                m_tabGSignIn,
                m_tabOptions,
                m_tabAbout,
                m_grpEntry,
                m_grpDriveAuth,
                m_lblAccount,
                m_lblClientId,
                m_lblClientSecret,
                m_chkDriveScope,
                m_chkLegacyClientId,
                m_grpDriveOptions,
                m_lblHintFolder,
                m_lblFolder,
                m_btnCancel,
                m_btnOK,
                m_grpCmdEnabled,
                m_chkSyncEnabled,
                m_chkUploadEnabled,
                m_chkDownloadEnabled,
                m_grpAutoSync,
                m_chkSyncOnOpen,
                m_chkSyncOnSave,
                m_grpDriveAuthDefaults,
                m_lblDefaultClientId,
                m_lblDefaultClientSecret,
                m_chkDefaultDriveScope,
                m_chkDefaultLegacyClientId,
                m_grpFolderDefaults,
                m_lblHintDefaultFolder,
                m_lblDefaultFolderLabel,
                m_lblDefFolderColor,
                m_btnGetColors,
                m_lblAttribution,
            };
            foreach (Control c in textCx)
            {
                c.Text = Resources.GetString(c.Text);
            }

            m_data = data;

            // Wire events and such for the folder color picker.
            m_nullColor = new GoogleColor(m_cbColors.BackColor,
                                          GoogleColor.Default.Name);
            m_cbColors.DrawMode              = DrawMode.OwnerDrawVariable;
            m_cbColors.DrawItem             += HandleColorsDrawItem;
            m_btnGetColors.Click            += HandleColorsComboLazyLoad;
            m_cbColors.SelectedIndexChanged += HandleColorsSelectedIndexChanged;
            if (m_data.DefaultAppFolderColor == null ||
                m_data.DefaultAppFolderColor == GoogleColor.Default)
            {
                m_cbColors.Items.Add(m_nullColor);
                m_cbColors.SelectedIndex = 0;
                m_cbColors.Enabled       = false;
            }
            else
            {
                GoogleColor[] userColors = new[]
                {
                    m_nullColor,
                    new GoogleColor(m_data.DefaultAppFolderColor.Color,
                                    m_data.DefaultAppFolderColor.Name)
                };
                m_cbColors.Items.Clear();
                m_cbColors.Items.AddRange(userColors);
                m_cbColors.SelectedItem = userColors[1];
                m_cbColors.Enabled      = string.IsNullOrWhiteSpace(m_txtFolderDefault.Text);
            }
            m_btnGetColors.Enabled = string.IsNullOrWhiteSpace(m_txtFolderDefault.Text);
            m_bColorsQueried       = false;
        }