1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* Copyright (C) 2013-2020 Graeme Gott <graeme@gottcode.org>
*
* This library 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 2 of the License, or
* (at your option) any later version.
*
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "icon-size.h"
#include "settings.h"
#include <glib/gi18n-lib.h>
using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
IconSize::IconSize(const gchar* property, const int size) :
m_property(property),
m_default(CLAMP(size, NONE, Largest)),
m_size(m_default)
{
}
//-----------------------------------------------------------------------------
int IconSize::get_size() const
{
int size = 0;
switch (m_size)
{
case NONE: size = 1; break;
case Smallest: size = 16; break;
case Smaller: size = 24; break;
case Small: size = 32; break;
case Normal: size = 48; break;
case Large: size = 64; break;
case Larger: size = 96; break;
case Largest: size = 128; break;
default: size = 0; break;
}
return size;
}
//-----------------------------------------------------------------------------
std::vector<std::string> IconSize::get_strings()
{
return {
_("None"),
_("Very Small"),
_("Smaller"),
_("Small"),
_("Normal"),
_("Large"),
_("Larger"),
_("Very Large")
};
}
//-----------------------------------------------------------------------------
void IconSize::load(XfceRc* rc, bool is_default)
{
set(xfce_rc_read_int_entry(rc, m_property + 1, m_size), !is_default);
if (is_default)
{
m_default = m_size;
}
}
//-----------------------------------------------------------------------------
bool IconSize::load(const gchar* property, const GValue* value)
{
if (g_strcmp0(m_property, property) != 0)
{
return false;
}
set(G_VALUE_HOLDS_INT(value) ? g_value_get_int(value) : m_default, false);
return true;
}
//-----------------------------------------------------------------------------
void IconSize::set(int size, bool store)
{
size = CLAMP(size, NONE, Largest);
if (m_size == size)
{
return;
}
m_size = size;
if (store && wm_settings->channel)
{
wm_settings->begin_property_update();
xfconf_channel_set_int(wm_settings->channel, m_property, m_size);
wm_settings->end_property_update();
}
}
//-----------------------------------------------------------------------------
|