// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2013 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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 .
*
* Authored by: Marco Trevisan (Treviño)
*/
#include "SessionView.h"
#include "SessionButton.h"
#include
#include
#include "unity-shared/RawPixel.h"
namespace unity
{
namespace session
{
namespace style
{
std::string const FONT = "Ubuntu Light";
std::string const TITLE_FONT = FONT+" 15";
std::string const SUBTITLE_FONT = FONT+" 12";
RawPixel const LEFT_RIGHT_PADDING = 30_em;
RawPixel const TOP_PADDING = 19_em;
RawPixel const BOTTOM_PADDING = 12_em;
RawPixel const MAIN_SPACE = 17_em;
RawPixel const BUTTONS_SPACE = 20_em;
}
NUX_IMPLEMENT_OBJECT_TYPE(View);
View::View(Manager::Ptr const& manager)
: mode(Mode::FULL)
, key_focus_area([this] { return key_focus_area_; })
, manager_(manager)
, key_focus_area_(this)
{
closable = true;
main_layout_ = new nux::VLayout();
SetLayout(main_layout_);
title_ = new StaticCairoText("");
title_->SetFont(style::TITLE_FONT);
title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
title_->SetInputEventSensitivity(false);
title_->SetVisible(false);
main_layout_->AddView(title_);
subtitle_ = new StaticCairoText("");
subtitle_->SetFont(style::SUBTITLE_FONT);
subtitle_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
subtitle_->SetInputEventSensitivity(false);
subtitle_->SetLines(std::numeric_limits::min());
subtitle_->SetLineSpacing(2);
main_layout_->AddView(subtitle_);
buttons_layout_ = new nux::HLayout();
main_layout_->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); });
have_inhibitors.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateText)));
manager_->have_other_open_sessions.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateText)));
mode.SetSetterFunction([this] (Mode& target, Mode new_mode) {
if (new_mode == Mode::SHUTDOWN && !manager_->CanShutdown())
new_mode = Mode::LOGOUT;
if (target != new_mode)
{
target = new_mode;
return true;
}
return false;
});
mode.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateContents)));
scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));
UpdateContents();
}
void View::UpdateContents()
{
SetVisible(true);
PopulateButtons();
UpdateText();
UpdateViewSize();
}
void View::UpdateViewSize()
{
main_layout_->SetTopAndBottomPadding(style::TOP_PADDING.CP(scale()), style::BOTTOM_PADDING.CP(scale()));
main_layout_->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING.CP(scale()));
main_layout_->SetSpaceBetweenChildren(style::MAIN_SPACE.CP(scale()));
title_->SetScale(scale());
subtitle_->SetScale(scale());
ReloadCloseButtonTexture();
buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));
auto const& buttons = buttons_layout_->GetChildren();
for (auto* area : buttons)
static_cast