Back to index

unity  6.0.0
ShortcutHint.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Andrea Azzarone <azzaronea@gmail.com>
00018  */
00019 
00020 #include "ShortcutHint.h"
00021 
00022 #include <core/core.h> // Compiz...
00023 #include <NuxCore/Logger.h>
00024 
00025 #include "ShortcutHintPrivate.h"
00026 
00027 namespace unity
00028 {
00029 namespace shortcut
00030 {
00031 namespace
00032 {
00033   nux::logging::Logger logger("unity.shortcut");
00034 } // anonymouse namespace 
00035 
00036 // Ctor
00037 Hint::Hint(std::string const& category,
00038            std::string const& prefix,
00039            std::string const& postfix,
00040            std::string const& description,
00041            OptionType const type,
00042            std::string const& arg1, 
00043            std::string const& arg2,
00044            std::string const& arg3)
00045   : AbstractHint(category, prefix, postfix, description, type, arg1, arg2, arg3)
00046 {
00047 }
00048 
00049 // Dtor
00050 Hint::~Hint()
00051 {
00052 }
00053 
00054 /*
00055  * Gets and fills the shortcut value. 
00056  * Returns true if everything was OK, returns false otherwise.
00057  * Use member property Value to get it.
00058  */
00059 bool Hint::Fill()
00060 {
00061   switch(type())
00062   {
00063     case COMPIZ_MOUSE_OPTION:
00064     {
00065       // Arg1 = Plugin name
00066       // Arg2 = key Option name
00067       CompPlugin* p = CompPlugin::find(arg1().c_str());
00068 
00069       if (!p) 
00070         return false;
00071 
00072       foreach (CompOption &opt, p->vTable->getOptions())
00073       {
00074           if (opt.name() == arg2())
00075           {
00076             std::string temp = impl::FixMouseShortcut(impl::FixShortcutFormat(opt.value().action().buttonToString()));
00077             temp = impl::ProperCase(temp);
00078             
00079             if (value() != temp)
00080             {
00081               value = temp;
00082               shortkey = prefix() + value() + postfix();
00083             }
00084               
00085             return true;
00086           }
00087       }
00088 
00089       break;
00090     }
00091     break;
00092     
00093     case COMPIZ_KEY_OPTION:
00094     {
00095       // Arg1 = Plugin name
00096       // Arg2 = key Option name
00097       CompPlugin* p = CompPlugin::find(arg1().c_str());
00098 
00099       if (!p) 
00100         return false;
00101 
00102       foreach (CompOption &opt, p->vTable->getOptions())
00103       {
00104           if (opt.name() == arg2())
00105           {
00106             std::string temp(impl::GetTranslatableLabel(opt.value().action().keyToString()));
00107             temp = impl::ProperCase(temp);
00108             
00109             if (value() != temp)
00110             {
00111               value = temp;
00112               shortkey = prefix() + value() + postfix();
00113             }
00114               
00115             return true;
00116           }
00117       }
00118 
00119       break;
00120     }
00121     case COMPIZ_METAKEY_OPTION:
00122     {
00123       // Arg1 = Plugin name
00124       // Arg2 = key Option name
00125       CompPlugin* p = CompPlugin::find(arg1().c_str());
00126 
00127       if (!p) 
00128         return false;
00129 
00130       foreach (CompOption &opt, p->vTable->getOptions())
00131       {
00132           if (opt.name() == arg2())
00133           {
00134             std::string temp(impl::GetMetaKey(opt.value().action().keyToString()));
00135             temp = impl::GetTranslatableLabel(temp);
00136             temp = impl::ProperCase(temp);
00137             
00138             if (value() != temp)
00139             {
00140               value = temp;
00141               shortkey = prefix() + value() + postfix();
00142             }
00143               
00144             return true;
00145           }
00146       }
00147 
00148       break;
00149     }
00150     case HARDCODED_OPTION:
00151       if (value != arg1())
00152       {
00153         value = arg1();
00154         shortkey = prefix() + value() + postfix();
00155       }
00156       return true;
00157 
00158     default:
00159       LOG_WARNING(logger) << "Unable to find the option type" << type(); 
00160   }
00161 
00162   return false;
00163 }
00164 
00165 } // namespace shortcut
00166 } // namespace unity