~sethj/ubuntu/wily/unity/fix-for-1445595

« back to all changes in this revision

Viewing changes to shutdown/StandaloneSession.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-02-11 22:41:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3200.
  • Revision ID: mail@3v1n0.net-20130211224112-k1nxtougs7xgdjj5
ShutdownView: first draft implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
 
2
/*
 
3
 * Copyright (C) 2013 Canonical Ltd
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License version 3 as
 
7
 * published by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Authored by: Marco Trevisan <marco@ubuntu.com>
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include <glib/gi18n-lib.h>
 
22
#include <gtk/gtk.h>
 
23
#include <Nux/Nux.h>
 
24
#include <Nux/NuxTimerTickSource.h>
 
25
#include <Nux/WindowThread.h>
 
26
#include <NuxCore/AnimationController.h>
 
27
#include <UnityCore/SessionManager.h>
 
28
 
 
29
#include "unity-shared/BackgroundEffectHelper.h"
 
30
#include "SessionController.h"
 
31
#include "unity-shared/UnitySettings.h"
 
32
 
 
33
using namespace unity;
 
34
 
 
35
class MockSessionManager : public session::Manager
 
36
{
 
37
public:
 
38
  MockSessionManager() = default;
 
39
 
 
40
  std::string RealName() const { return "Marco Trevisan"; }
 
41
  std::string UserName() const { return "marco"; }
 
42
 
 
43
  void Logout() { std::cout << "Logout" << std::endl; }
 
44
  void Reboot() { std::cout << "Reboot" << std::endl; }
 
45
  void Shutdown() { std::cout << "Shutdown" << std::endl; }
 
46
  void Suspend() { std::cout << "Suspend" << std::endl; }
 
47
  void Hibernate() { std::cout << "Hibernate" << std::endl; }
 
48
 
 
49
  void ConfirmLogout() { std::cout << "ConfirmLogout" << std::endl; }
 
50
  void ConfirmReboot() { std::cout << "ConfirmReboot" << std::endl; }
 
51
  void ConfirmShutdown() { std::cout << "ConfirmShutdown" << std::endl; }
 
52
  void CancelAction() { std::cout << "CancelAction" << std::endl; }
 
53
  void ClosedDialog() { std::cout << "ClosedDialog" << std::endl; }
 
54
 
 
55
  bool CanShutdown() const {return true;}
 
56
  bool CanSuspend() const {return true;}
 
57
  bool CanHibernate() const {return false;}
 
58
};
 
59
 
 
60
namespace unity
 
61
{
 
62
namespace session
 
63
{
 
64
struct StandaloneController : Controller
 
65
{
 
66
  StandaloneController(session::Manager::Ptr const& manager)
 
67
    : Controller(manager)
 
68
  {}
 
69
 
 
70
  nux::Point GetOffsetPerMonitor(int monitor) override
 
71
  {
 
72
    return nux::Point();
 
73
  }
 
74
};
 
75
}
 
76
}
 
77
 
 
78
struct SessionWindow
 
79
{
 
80
  SessionWindow()
 
81
    : wt(nux::CreateGUIThread("Unity Session Controller", 1024, 300, 0, &SessionWindow::ThreadWidgetInit, this))
 
82
    , animation_controller(tick_source)
 
83
  {}
 
84
 
 
85
  void Show()
 
86
  {
 
87
    wt->Run(nullptr);
 
88
  }
 
89
 
 
90
private:
 
91
  void Init();
 
92
 
 
93
  static void ThreadWidgetInit(nux::NThread* thread, void* self)
 
94
  {
 
95
    static_cast<SessionWindow*>(self)->Init();
 
96
  }
 
97
 
 
98
  unity::Settings settings;
 
99
  std::shared_ptr<nux::WindowThread> wt;
 
100
  nux::NuxTimerTickSource tick_source;
 
101
  nux::animation::AnimationController animation_controller;
 
102
  session::Controller::Ptr controller;
 
103
};
 
104
 
 
105
void SessionWindow::Init()
 
106
{
 
107
  BackgroundEffectHelper::blur_type = BLUR_NONE;
 
108
  auto manager = std::make_shared<MockSessionManager>();
 
109
  controller = std::make_shared<session::StandaloneController>(manager);
 
110
  controller->Show();
 
111
}
 
112
 
 
113
int main(int argc, char** argv)
 
114
{
 
115
  gtk_init(&argc, &argv);
 
116
 
 
117
  nux::NuxInitialize(0);
 
118
  SessionWindow().Show();
 
119
 
 
120
  return 0;
 
121
}