~diodon-team/diodon/debian-packaging

« back to all changes in this revision

Viewing changes to libdiodon/clipboard-manager.vala

  • Committer: Oliver Sauder
  • Date: 2017-08-19 15:13:10 UTC
  • mfrom: (1.1.5)
  • Revision ID: os@esite.ch-20170819151310-slpjq8hflly52b56
ImportĀ upstreamĀ versionĀ 1.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        protected ClipboardType type;
32
32
        protected Gtk.Clipboard _clipboard = null;
33
33
        protected ClipboardConfiguration _configuration;
34
 
        
 
34
 
35
35
        /**
36
36
         * Called when text from the clipboard has been received
37
 
         * 
 
37
         *
38
38
         * @param type type of clipboard text belongs to
39
39
         * @param text received text from clipboard which is never null or empty
40
40
         */
41
41
        public signal void on_text_received(ClipboardType type, string text, string? origin);
42
 
        
 
42
 
43
43
        /**
44
44
         * Called when uris have been received from clipboard.
45
45
         * The given paths are not uris appended with file://
49
49
         * @param paths paths separated with /n.
50
50
         */
51
51
        public signal void on_uris_received(ClipboardType type, string paths, string? origin);
52
 
        
 
52
 
53
53
        /**
54
54
         * Called when a image has been received from the clipboard.
55
55
         *
57
57
         * @param pixbuf image as a pixbuf object
58
58
         */
59
59
        public signal void on_image_received(ClipboardType type, Gdk.Pixbuf pixbuf, string? origin);
60
 
        
 
60
 
61
61
        /**
62
62
         * Called when the clipboard is empty
63
63
         *
64
64
         * @param type type of clipboard which is empty
65
65
         */
66
66
        public signal void on_empty(ClipboardType type);
67
 
        
 
67
 
68
68
        /**
69
69
         * get type of given clipboard manager
70
70
         */
71
71
        public ClipboardType clipboard_type { get { return type; } }
72
 
        
 
72
 
73
73
        /**
74
74
         * Constructor
75
75
         *
85
85
            } else if(type == ClipboardType.PRIMARY) {
86
86
                _clipboard = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY);
87
87
            }
88
 
            
 
88
 
89
89
            this.type = type;
90
90
            this._configuration = configuration;
91
91
        }
92
 
        
 
92
 
93
93
        /**
94
94
         * Starts the process requesting data from encapsulated clipboard.
95
95
         * The owner has to change when new data is set in the clipboard
99
99
        {
100
100
            _clipboard.owner_change.connect(check_clipboard);
101
101
        }
102
 
        
 
102
 
103
103
        /**
104
104
         * Stop the process requesting data from encapsulated clipboard.
105
105
         */
107
107
        {
108
108
            _clipboard.owner_change.disconnect(check_clipboard);
109
109
        }
110
 
        
 
110
 
111
111
        /**
112
112
         * Select item in the managed clipboard.
113
113
         *
117
117
        {
118
118
            item.to_clipboard(_clipboard);
119
119
        }
120
 
        
 
120
 
121
121
        /**
122
 
         * Clear managed clipboard 
 
122
         * Clear managed clipboard
123
123
         */
124
124
        public void clear()
125
125
        {
129
129
            //clipboard.clear();
130
130
            _clipboard.set_text("", -1);
131
131
        }
132
 
        
 
132
 
133
133
        /**
134
134
         * Request text from managed clipboard. If result is valid
135
135
         * on_text_received will be called.
144
144
            bool text_available = (text != null && text != "") || _clipboard.wait_is_text_available();
145
145
            bool image_available = _configuration.add_images && _clipboard.wait_is_image_available();
146
146
            bool uris_available = _clipboard.wait_is_uris_available();
147
 
            
 
147
 
148
148
            // checking if any content known is available
149
149
            if(text_available || image_available || uris_available) {
150
150
                string? origin = Utility.get_path_of_active_application();
151
 
                
 
151
 
152
152
                // checking for uris
153
153
                if(text_available) {
154
154
                    // check if text is valid
174
174
                check_clipboard_emptiness();
175
175
            }
176
176
        }
177
 
        
 
177
 
178
178
        /**
179
179
         * Request image from clipboard and return it
180
180
         *
185
185
            Gdk.Pixbuf? result = _clipboard.wait_for_image();
186
186
            return result;
187
187
        }
188
 
        
 
188
 
189
189
        /**
190
190
         * request text from clipboard and return it
191
191
         *
196
196
            string? result = _clipboard.wait_for_text();
197
197
            return result;
198
198
        }
199
 
        
 
199
 
200
200
        /**
201
201
         * Check if clipboard content has been lost.
202
202
         */
207
207
                on_empty(type);
208
208
            }
209
209
        }
210
 
    }  
 
210
    }
211
211
}
212
 
 
 
212