Commits

HexRx committed 026e402

Add the state manager

  • Participants
  • Parent commits 323bde9

Comments (0)

Files changed (1)

KPDataSave/Forms/StateControl.cs

+/*
+    KPDataSave - KeePass plugin which saves database in Dropbox service
+    Copyright (C) 2011-2012 HexRx
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+using DropboxAPI;
+using KPDataSave.Forms.States;
+using KeePass.Plugins;
+
+namespace KPDataSave.Forms
+{
+    public class StateControl
+    {
+        private readonly Form _signInState;
+        private readonly Form _acceptState;
+        private readonly Form _selectFolder;
+
+        // Хранит текущее состояние
+        private Form _currentState;
+
+        // Объект отвечающий за взаимодействие с сервисом
+        private readonly DropboxClient _dropboxClient;
+
+        // Объект KeePass для работы с плагинам
+        private readonly IPluginHost _host;
+
+        public StateControl(IPluginHost host)
+        {
+            _host = host;
+            _dropboxClient = new DropboxClient("hhekhlyshoqxt5s", "h0oh21e8y2seixx");
+            _signInState = new SignIn(this);
+            _acceptState = new Accept(this);
+            _selectFolder = new SelectFolder(this);
+            // Начальное состояние
+            SetState(SignInState);
+        }
+
+        // Установка состояния
+        public void SetState(Form state)
+        {
+            // Если установлено состояние, то скрываем форму
+            if (_currentState != null)
+                _currentState.Hide();
+            _currentState = state;
+            // Отображаем форму
+            _currentState.Show();
+        }
+
+        public Form AcceptState
+        {
+            get { return _acceptState; }
+        }
+
+        public Form SignInState
+        {
+            get { return _signInState; }
+        }
+
+        public Form SelectFolderState
+        {
+            get { return _selectFolder; }
+        }
+
+        public DropboxClient DropboxClient
+        {
+            get { return _dropboxClient; }
+        }
+
+        public IPluginHost PluginHost
+        {
+            get { return _host; }
+        }
+    }
+}