~brandontschaefer/unity/fix-915828

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/ShortcutHint.cpp

  • Committer: Brandon Schaefer
  • Date: 2012-02-02 04:05:22 UTC
  • mfrom: (1827.1.59 unity)
  • Revision ID: brandontschaefer@gmail.com-20120202040522-r86246d1fxmclh4p
merged

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) 2011 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: Andrea Azzarone <azzaronea@gmail.com>
 
18
 */
 
19
 
 
20
#include "ShortcutHint.h"
 
21
 
 
22
#include <core/core.h> // Compiz...
 
23
#include <NuxCore/Logger.h>
 
24
 
 
25
#include "ShortcutHintPrivate.h"
 
26
 
 
27
namespace unity
 
28
{
 
29
namespace shortcut
 
30
{
 
31
namespace
 
32
{
 
33
  nux::logging::Logger logger("unity.shortcut");
 
34
} // anonymouse namespace 
 
35
 
 
36
// Ctor
 
37
Hint::Hint(std::string const& category,
 
38
           std::string const& prefix,
 
39
           std::string const& postfix,
 
40
           std::string const& description,
 
41
           OptionType const type,
 
42
           std::string const& arg1, 
 
43
           std::string const& arg2,
 
44
           std::string const& arg3)
 
45
  : AbstractHint(category, prefix, postfix, description, type, arg1, arg2, arg3)
 
46
{
 
47
}
 
48
 
 
49
// Dtor
 
50
Hint::~Hint()
 
51
{
 
52
}
 
53
 
 
54
/*
 
55
 * Gets and fills the shortcut value. 
 
56
 * Returns true if everything was OK, returns false otherwise.
 
57
 * Use member property Value to get it.
 
58
 */
 
59
bool Hint::Fill()
 
60
{
 
61
  switch(type())
 
62
  {
 
63
    case COMPIZ_MOUSE_OPTION:
 
64
    {
 
65
      // Arg1 = Plugin name
 
66
      // Arg2 = key Option name
 
67
      CompPlugin* p = CompPlugin::find(arg1().c_str());
 
68
 
 
69
      if (!p) 
 
70
        return false;
 
71
 
 
72
      foreach (CompOption &opt, p->vTable->getOptions())
 
73
      {
 
74
          if (opt.name() == arg2())
 
75
          {
 
76
            std::string temp = impl::FixMouseShortcut(impl::FixShortcutFormat(opt.value().action().buttonToString()));
 
77
            temp = impl::ProperCase(temp);
 
78
            
 
79
            if (value() != temp)
 
80
            {
 
81
              value = temp;
 
82
              shortkey = prefix() + value() + postfix();
 
83
            }
 
84
              
 
85
            return true;
 
86
          }
 
87
      }
 
88
 
 
89
      break;
 
90
    }
 
91
    break;
 
92
    
 
93
    case COMPIZ_KEY_OPTION:
 
94
    {
 
95
      // Arg1 = Plugin name
 
96
      // Arg2 = key Option name
 
97
      CompPlugin* p = CompPlugin::find(arg1().c_str());
 
98
 
 
99
      if (!p) 
 
100
        return false;
 
101
 
 
102
      foreach (CompOption &opt, p->vTable->getOptions())
 
103
      {
 
104
          if (opt.name() == arg2())
 
105
          {
 
106
            std::string temp = impl::FixShortcutFormat(opt.value().action().keyToString());
 
107
            temp = impl::ProperCase(temp);
 
108
            
 
109
            if (value() != temp)
 
110
            {
 
111
              value = temp;
 
112
              shortkey = prefix() + value() + postfix();
 
113
            }
 
114
              
 
115
            return true;
 
116
          }
 
117
      }
 
118
 
 
119
      break;
 
120
    }
 
121
    case HARDCODED_OPTION:
 
122
      if (value != arg1())
 
123
      {
 
124
        value = arg1();
 
125
        shortkey = prefix() + value() + postfix();
 
126
      }
 
127
      return true;
 
128
 
 
129
    default:
 
130
      LOG_WARNING(logger) << "Unable to find the option type" << type(); 
 
131
  }
 
132
 
 
133
  return false;
 
134
}
 
135
 
 
136
} // namespace shortcut
 
137
} // namespace unity