~mial/ubuntu/oneiric/unity/bug-791810

« back to all changes in this revision

Viewing changes to unity-private/utils.vala

Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by Neil Jagdish Patel <neil.patel@canonical.com>
 
17
 *
 
18
 */
 
19
 
 
20
namespace Utils
 
21
{
 
22
  string strip_characters (string text,
 
23
                           string replace_text,
 
24
                           string match_regex,
 
25
                           string replace_regex)
 
26
  {
 
27
    string         ret = "";
 
28
    bool           matching = false;
 
29
    GLib.MatchInfo info;
 
30
 
 
31
    {
 
32
      GLib.Regex regex = null;
 
33
 
 
34
      try
 
35
        {
 
36
          regex = new GLib.Regex (match_regex,
 
37
                                  GLib.RegexCompileFlags.DOTALL |
 
38
                                  GLib.RegexCompileFlags.OPTIMIZE,
 
39
                                  0);
 
40
        }
 
41
      catch (GLib.RegexError e)
 
42
        {
 
43
          warning ("Creating regular-expression failed: \"%s\"\n", e.message);
 
44
        }
 
45
 
 
46
      matching = regex.match (text, 0, out info);
 
47
    }
 
48
 
 
49
    if (matching)
 
50
      {
 
51
        GLib.Regex regex = null;
 
52
 
 
53
        try
 
54
          {
 
55
            regex = new GLib.Regex (replace_regex,
 
56
                                    GLib.RegexCompileFlags.DOTALL |
 
57
                                    GLib.RegexCompileFlags.OPTIMIZE,
 
58
                                    0);
 
59
          }
 
60
        catch (GLib.RegexError e)
 
61
          {
 
62
            warning ("Creating regular-expression failed: \"%s\"\n", e.message);
 
63
          }
 
64
 
 
65
        try
 
66
          {
 
67
            ret = regex.replace (text, -1, 0, replace_text, 0);
 
68
          }
 
69
        catch (GLib.RegexError e)
 
70
          {
 
71
            warning ("Replacing text failed: \"%s\"\n", e.message);
 
72
          }
 
73
      }
 
74
    else
 
75
      ret = text;
 
76
 
 
77
    return ret;
 
78
  }
 
79
 
 
80
  [CCode (lower_case_prefix = "utils_")]
 
81
  public extern void set_strut (Gtk.Window *window,
 
82
                                  uint32    strut_size,
 
83
                                  uint32    strut_start,
 
84
                                  uint32    strut_end,
 
85
                                  uint32    top_size,
 
86
                                  uint32    top_start,
 
87
                                  uint32    top_end);
 
88
 
 
89
  [CCode (lower_case_prefix = "utils_")]
 
90
  public extern void register_object_on_dbus (DBus.Connection conn,
 
91
                                              string path,
 
92
                                              GLib.Object object);
 
93
 
 
94
  [CCode (lower_case_prefix = "utils_")]
 
95
  public extern X.Window get_stage_window (Clutter.Stage stage);
 
96
 
 
97
  [CCode (lower_case_prefix = "utils_")]
 
98
  public extern bool save_snapshot (Clutter.Stage stage,
 
99
                                    string        filename,
 
100
                                    int           x,
 
101
                                    int           y,
 
102
                                    int           width,
 
103
                                    int           height);
 
104
 
 
105
  [CCode (lower_case_prefix = "utils_")]
 
106
  public extern bool compare_snapshot (Clutter.Stage stage,
 
107
                                       string        filename,
 
108
                                       int           x,
 
109
                                       int           y,
 
110
                                       int           width,
 
111
                                       int           height,
 
112
                                       bool          expected=true);
 
113
 
 
114
 
 
115
  [CCode (lower_case_prefix = "utils_")]
 
116
  public extern bool utils_compare_images (string img1_path,
 
117
                                           string img2_path);
 
118
 
 
119
  [CCode (lower_case_prefix = "utils_")]
 
120
  public extern bool window_is_decorated (X.Window window);
 
121
 
 
122
  [CCode (lower_case_prefix = "utils_")]
 
123
  public extern void window_set_decorations (X.Window window, uint decorations);
 
124
 
 
125
  [CCode (lower_case_prefix = "utils_")]
 
126
  public extern void volume_eject (GLib.Volume volume);
 
127
}