KPDataSave / 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
    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 <>.

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 Form _currentState;

        // Объект отвечающий за взаимодействие с сервисом
        private readonly DropboxClient _dropboxClient;

        // Объект KeePass для работы с плагинам
        private readonly IPluginHost _host;

        public StateControl(IPluginHost host)
            _host = host;
            _dropboxClient = new DropboxClient("hhekhlyshoqxt5s", "h0oh21e8y2seixx");

            AccountState accountState = AccountState.Deserialize(host);
            // Начальное состояние
            SetState(accountState == null ? SignInState : new SignOut(this));

        // Установка состояния
        public void SetState(Form state)
            // Если установлено состояние, то скрываем форму
            if (_currentState != null)
            _currentState = state;
            // Отображаем форму

        public Form AcceptState
            get { return new Accept(this); }

        public Form SignInState
            get { return new SignIn(this); }

        public Form SelectFolderState
            get { return new SelectFolder(this); }

        public DropboxClient DropboxClient
            get { return _dropboxClient; }

        public IPluginHost PluginHost
            get { return _host; }