1 2[CCode (cprefix = "Cb", lower_case_cprefix = "cb_")] 3namespace Cb { 4 [CCode (cprefix = "CB_MEDIA_TYPE_", cheader_filename = "CbMedia.h")] 5 public enum MediaType { 6 IMAGE, 7 GIF, 8 ANIMATED_GIF, 9 TWITTER_VIDEO, 10 INSTAGRAM_VIDEO, 11 12 UNKNOWN 13 } 14 15 [CCode (cprefix = "CB_STREAM_MESSAGE_", cheader_filename = "CbUserStream.h")] 16 public enum StreamMessageType { 17 UNSUPPORTED, 18 DELETE, 19 DM_DELETE, 20 RT_DELETE, 21 SCRUB_GEO, 22 LIMIT, 23 DISCONNECT, 24 FRIENDS, 25 EVENT, 26 WARNING, 27 DIRECT_MESSAGE, 28 29 TWEET, 30 MENTION, 31 EVENT_LIST_CREATED, 32 EVENT_LIST_DESTROYED, 33 EVENT_LIST_UPDATED, 34 EVENT_LIST_UNSUBSCRIBED, 35 EVENT_LIST_SUBSCRIBED, 36 EVENT_LIST_MEMBER_ADDED, 37 EVENT_LIST_MEMBER_REMOVED, 38 EVENT_FAVORITE, 39 EVENT_UNFAVORITE, 40 EVENT_FOLLOW, 41 EVENT_UNFOLLOW, 42 EVENT_BLOCK, 43 EVENT_UNBLOCK, 44 EVENT_MUTE, 45 EVENT_UNMUTE, 46 EVENT_USER_UPDATE, 47 EVENT_QUOTED_TWEET, 48 EVENT_HIDE_RTS, 49 EVENT_SHOW_RTS, 50 51 TIMELINE_LOADED, 52 MENTIONS_LOADED, 53 FAVORITES_LOADED, 54 DIRECT_MESSAGES_LOADED 55 } 56 57 [CCode (cprefix = "CbMedia_", lower_case_cprefix = "cb_media_", cheader_filename = "CbMedia.h")] 58 public class Media : GLib.Object { 59 public int64 length; 60 public bool loading; 61 public bool loaded; 62 public bool loading_hires; 63 public bool loaded_hires; 64 public bool invalid; 65 public string consumer_key; 66 public string consumer_secret; 67 public string token; 68 public string token_secret; 69 public string url; 70 public string thumb_url; 71 public string target_url; 72 public string alt_text; 73 public MediaType type; 74 public int width; 75 public int height; 76 public int thumb_width; 77 public int thumb_height; 78 public double percent_loaded; 79 public double percent_loaded_hires; 80 public Cairo.ImageSurface? surface; 81 public Cairo.ImageSurface? surface_hires; 82 public Gdk.PixbufAnimation? animation; 83 public signal void progress(); 84 85 public Media(); 86 public bool is_video (); 87 public bool requires_authentication(); 88 } 89 90 [CCode (cprefix = "CbUserIdentity_", lower_case_cprefix = "cb_user_identity_", cheader_filename = "CbTypes.h", 91 destroy_function = "cb_user_identity_free")] 92 public struct UserIdentity { 93 public int64 id; 94 public string screen_name; 95 public string user_name; 96 public bool verified; 97 public bool protected_account; 98 public void parse (Json.Object object); 99 } 100 101 /* Needed for unit tests */ 102 [CCode (cprefix = "CbMediaDownloader", lower_case_cprefix = "cb_media_downloader_", 103 cheader_filename = "CbMediaDownloader.h")] 104 public class MediaDownloader : GLib.Object { 105 public static unowned MediaDownloader get_default (); 106 public async void load_async (Media media); 107 public async void reload_async (Media media); 108 public async void load_hires_async (Media media); 109 public void disable (); 110 public void shutdown (); 111 } 112 113 [CCode (cprefix = "CbTextEntity", lower_case_cprefix = "cb_text_entity_", cheader_filename = "CbTypes.h", 114 destroy_function = "cb_text_entity_free")] 115 public struct TextEntity { 116 public uint from; 117 public uint to; 118 public string original_text; 119 public string display_text; 120 public string tooltip_text; 121 public string? target; // If target is null, use display_text as target! 122 public uint info; 123 } 124 125 [CCode (cprefix = "CbMiniTweet", lower_case_cprefix = "cb_mini_tweet_", cheader_filename = "CbTypes.h", 126 destroy_function = "cb_mini_tweet_free")] 127 public struct MiniTweet { 128 public int64 id; 129 public int64 created_at; 130 public uint display_range_start; 131 public int64 reply_id; 132 public Cb.UserIdentity author; 133 public string text; 134 [CCode (array_length_cname = "n_entities", array_length_type = "size_t")] 135 public Cb.TextEntity[] entities; 136 [CCode (array_length_cname = "n_medias", array_length_type = "size_t")] 137 public Cb.Media[] medias; 138 [CCode (array_length_cname = "n_reply_users", array_length_type = "size_t")] 139 public Cb.UserIdentity[] reply_users; 140 141 [CCode (cname = "cb_mini_tweet_init")] 142 public MiniTweet(); 143 public void parse (Json.Object obj); 144 public void parse_entities (Json.Object status); 145 } 146 147 [CCode (cprefix = "CbTweet", lower_case_cprefix = "cb_tweet_", cheader_filename = "CbTweet.h")] 148 public class Tweet : GLib.Object { 149 [CCode (cname = "CB_TWEET_MAX_LENGTH")] 150 public static int MAX_LENGTH; 151 public Cb.MiniTweet source_tweet; 152 public Cb.MiniTweet? retweeted_tweet; 153 public Cb.MiniTweet? quoted_tweet; 154 public int64 id; 155 public int64 my_retweet; 156 public int favorite_count; 157 public int retweet_count; 158 public string avatar_url; 159 160 public Tweet(); 161 162 public int64 get_user_id (); 163 public unowned string get_screen_name (); 164 public unowned string get_user_name (); 165 166 public unowned string get_language (); 167 168 public bool has_inline_media (); 169 public bool has_quoted_inline_media (); 170 public void load_from_json (Json.Node node, int64 account_id, GLib.DateTime now); 171 172 public bool is_reply (); 173 174 public bool is_flag_set (uint flag); 175 public void set_flag (uint flag); 176 public void unset_flag (uint flag); 177 178 public bool is_quoted_flag_set (uint flag); 179 public void set_quoted_flag (uint flag); 180 public void unset_quoted_flag (uint flag); 181 182 public string get_formatted_text (); 183 public string get_trimmed_text (uint transform_flags); 184 public string get_real_text (); 185 public string get_filter_text (); 186 187 public unowned Cb.UserIdentity[] get_reply_users (); 188 189 public unowned Cb.Media[] get_medias(); 190 public unowned Cb.Media[] get_quoted_medias(); 191 public string[] get_mentions(); 192 193 public signal void state_changed(); 194 public bool is_hidden (); 195 public string? notification_id; 196 197 public bool get_seen (); 198 public void set_seen (bool val); 199 200 public uint state; 201#if DEBUG 202 public string json_data; 203#endif 204 } 205 206 [CCode (cprefix = "CB_TWEET_STATE_", lower_case_cprefix = "CbTweetState", cheader_filename = "CbTweet.h")] 207 [Flags] 208 public enum TweetState { 209 HIDDEN_FORCE, 210 HIDDEN_UNFOLLOWED, 211 HIDDEN_FILTERED, 212 HIDDEN_RTS_DISABLED, 213 HIDDEN_RT_BY_USER, 214 HIDDEN_RT_BY_FOLLOWEE, 215 HIDDEN_AUTHOR_BLOCKED, 216 HIDDEN_RETWEETER_BLOCKED, 217 HIDDEN_AUTHOR_MUTED, 218 HIDDEN_RETWEETER_MUTED, 219 220 RETWEETED, 221 FAVORITED, 222 DELETED, 223 VERIFIED, 224 PROTECTED, 225 NSFW 226 } 227 228 [CCode (cprefix = "CB_TEXT_TRANSFORM_", lower_case_cprefix = "CbTextTransformFlags", cheader_filename = "CbTextTransform.h")] 229 public enum TransformFlags { 230 REMOVE_TRAILING_HASHTAGS, 231 EXPAND_LINKS, 232 REMOVE_MEDIA_LINKS 233 } 234 235 [CCode (cprefix = "cb_text_transform_", cheader_filename = "CbTextTransform.h")] 236 namespace TextTransform { 237 string tweet (ref MiniTweet tweet, uint flags, int64 quote_id); 238 string text (string text, TextEntity[] entities, uint flags, size_t n_medias, int64 quote_id, uint display_range_start = 0); 239 string fix_encoding (string text); 240 } 241 242 [CCode (cprefix = "cb_filter_", cheader_filename = "CbFilter.h")] 243 public class Filter : GLib.Object { 244 public Filter(string expr); 245 public bool matches (string text); 246 public void reset (string expr); 247 public unowned string get_contents(); 248 public int get_id (); 249 public void set_id (int id); 250 } 251 252 [CCode (cprefix = "cb_avatar_cache_", cheader_filename = "CbAvatarCache.h")] 253 class AvatarCache : GLib.Object { 254 public AvatarCache (); 255 public void add (int64 user_id, Cairo.Surface? surface, string? avatar_url); 256 public void increase_refcount_for_surface (Cairo.Surface surface); 257 public void decrease_refcount_for_surface (Cairo.Surface surface); 258 public void set_url (int64 user_id, string url); 259 public void set_avatar (int64 user_id, Cairo.Surface? surface, string url); 260 public unowned Cairo.Surface? get_surface_for_id (int64 user_id, out bool found); 261 public unowned string? get_url_for_id (int64 user_id); 262 public uint get_n_entries (); 263 } 264 265 [CCode (cprefix = "cb_user_counter_", cheader_filename = "CbUserCounter.h")] 266 public class UserCounter : GLib.Object { 267 public UserCounter (); 268 public void id_seen (ref Cb.UserIdentity id); 269 public void user_seen (int64 id, string screen_name, string user_name); 270 public void user_seen_full (int64 id, string screen_name, string user_name, bool verified, bool protected_account); 271 public int save (Sqlite.Database db); 272 public void query_by_prefix (Sqlite.Database db, 273 string prefix, 274 int max_results, 275 out Cb.UserInfo[] infos); 276 } 277 278 [CCode (cheader_filename = "CbUserCounter.h")] 279 public struct UserInfo { 280 int64 user_id; 281 string screen_name; 282 string user_name; 283 int score; 284 bool changed; 285 bool verified; 286 bool protected_account; 287 } 288 289 290 [CCode (cprefix = "CbMediaImageWidget_", lower_case_cprefix = "cb_media_image_widget_", cheader_filename = 291 "CbMediaImageWidget.h")] 292 public class MediaImageWidget : Gtk.ScrolledWindow { 293 public MediaImageWidget (Media media, Gdk.Rectangle max_dimensions); 294 public void scroll_to (double x, double y); 295 } 296 297 [CCode (cprefix = "CbTweetModel_", lower_case_cprefix = "cb_tweet_model_", cheader_filename = 298 "CbTweetModel.h")] 299 public class TweetModel : GLib.Object, GLib.ListModel { 300 public int64 min_id; 301 public int64 max_id; 302 public GLib.GenericArray<Tweet> hidden_tweets; 303 304 public TweetModel (); 305 public void set_thread_mode (bool thread_mode); 306 public bool contains_id (int64 id); 307 public int index_of (int64 id); 308 public int index_of_retweet (int64 id); 309 public void clear (); 310 public unowned Tweet? get_for_id (int64 id, int diff = 0); 311 public void add (Tweet t); 312 public void remove_oldest_n_visible (uint amount); 313 public bool delete_id (int64 id, out bool seen); 314 public bool set_tweet_flag (Tweet t, TweetState flag); 315 public bool unset_tweet_flag (Tweet t, TweetState flag); 316 public void remove_tweet (Tweet t); 317 public void remove_tweets_later_than (int64 id); 318 public void toggle_flag_on_user_tweets (int64 user_id, TweetState flag, bool active); 319 public void toggle_flag_on_user_retweets (int64 user_id, TweetState flag, bool active); 320 } 321 322 [CCode (cprefix = "CbTwitterItemInterface_", lower_case_cprefix = "cb_twitter_item_", cheader_filename = 323 "CbTwitterItem.h", type_cname = "CbTwitterItemInterface")] 324 public interface TwitterItem : GLib.Object { 325 public abstract int64 get_sort_factor(); 326 public abstract int64 get_timestamp(); 327 public abstract int update_time_delta (GLib.DateTime? now = null); 328 public abstract void set_last_set_timediff (GLib.TimeSpan span); 329 public abstract GLib.TimeSpan get_last_set_timediff (); 330 } 331 332 [CCode (cprefix = "CbMessageReceiverInterface_", lower_case_cprefix = "cb_message_receiver_", cheader_filename = 333 "CbMessageReceiver.h", type_cname = "CbMessageReceiverInterface")] 334 public interface MessageReceiver : GLib.Object { 335 public abstract void stream_message_received (Cb.StreamMessageType type, 336 Json.Node node); 337 } 338 339 340 [CCode (cprefix = "CbDeltaUpdater_", lower_case_cprefix = "cb_delta_updater_", cheader_filename = 341 "CbDeltaUpdater.h")] 342 public class DeltaUpdater : GLib.Object { 343 public DeltaUpdater (Gtk.Widget listbox); 344 } 345 346 [CCode (cprefix = "CbUtils_", lower_case_cprefix = "cb_utils_", cheader_filename = 347 "CbUtils.h")] 348 namespace Utils { 349 public void init_gui ([CCode (array_length_pos = 0.1)] ref unowned string[] args); 350 public delegate Gtk.Widget CreateWidgetFunc (void *item); 351 public void bind_model (Gtk.Widget listbox, GLib.ListModel model, Gtk.ListBoxCreateWidgetFunc func); 352 public void bind_non_gobject_model (Gtk.Widget listbox, GLib.ListModel model, Cb.Utils.CreateWidgetFunc func); 353 public void unbind_non_gobject_model (Gtk.Widget *listbox, GLib.ListModel model); 354 public void linkify_user (ref Cb.UserIdentity id, GLib.StringBuilder str); 355 public GLib.DateTime parse_date (string _in); 356 public string get_file_type (string url); 357 public string rest_proxy_call_to_string (Rest.ProxyCall c); 358 public async Json.Node? load_threaded_async (Rest.ProxyCall call, GLib.Cancellable? cancellable) throws GLib.Error; 359 public async UserIdentity[] query_users_async (Rest.Proxy p, string q, GLib.Cancellable? cancellable) throws GLib.Error; 360 } 361 362 [CCode (cprefix = "CbBundle_", lower_case_cprefix = "cb_bundle_", cheader_filename = 363 "CbBundle.h")] 364 public class Bundle : GLib.Object { 365 public Bundle (); 366 367 public void put_string (int key, string val); 368 public unowned string get_string (int key); 369 370 public void put_int (int key, int val); 371 public int get_int (int key); 372 373 public void put_int64 (int key, int64 val); 374 public int64 get_int64 (int key); 375 376 public void put_bool (int key, bool val); 377 public bool get_bool (int key); 378 379 public void put_object (int key, GLib.Object val); 380 public unowned GLib.Object get_object (int key); 381 382 public bool equals (Bundle? other); 383 } 384 385 [CCode (cprefix = "CbBundleHistory_", lower_case_cprefix = "cb_bundle_history_", cheader_filename = 386 "CbBundleHistory.h")] 387 public class BundleHistory : GLib.Object { 388 public BundleHistory (); 389 390 public void push (int v, Cb.Bundle? b); 391 public int forward (); 392 public int back (); 393 public bool at_start (); 394 public bool at_end (); 395 396 public void remove_current (); 397 398 public int get_current (); 399 public unowned Cb.Bundle? get_current_bundle (); 400 401 } 402 [CCode (cprefix = "CbSnippetManager_", lower_case_cprefix = "cb_snippet_manager_", cheader_filename = 403 "CbSnippetManager.h")] 404 public class SnippetManager : GLib.Object { 405 public SnippetManager (Sqlite.Database db); 406 public unowned string get_snippet (string key); 407 public bool has_snippet_n (string key, size_t key_len); 408 public uint n_snippets (); 409 public void query_snippets (GLib.HFunc func); 410 public void set_snippet (string old_key, string key, string value); 411 public void remove_snippet (string key); 412 public void insert_snippet (string key, string value); 413 } 414 [CCode (cprefix = "CbMediaVideoWidget_", lower_case_cprefix = "cb_media_video_widget_", cheader_filename = 415 "CbMediaVideoWidget.h")] 416 public class MediaVideoWidget : Gtk.Stack { 417 public MediaVideoWidget (Media media, Gdk.Rectangle max_dimensions); 418 public void start (); 419 } 420 421 [CCode (cprefix = "CbUserStream_", lower_case_cprefix = "cb_user_stream_", cheader_filename = 422 "CbUserStream.h")] 423 public class UserStream : GLib.Object { 424 public UserStream (string name, Rest.OAuthProxy proxy); 425 public void register (MessageReceiver r); 426 public void unregister (MessageReceiver r); 427 public void push_data (string data); 428 public void start (); 429 public void stop (); 430 public void set_proxy_data (string a, string b); 431 public void inject_tweet (Cb.StreamMessageType message_type, string content); 432 433 public signal void interrupted (); 434 public signal void resumed (); 435 } 436 437 [CCode (cprefix = "CbComposeJob_", lower_case_cprefix = "cb_compose_job_", cheader_filename = 438 "CbComposeJob.h")] 439 public class ComposeJob : GLib.Object { 440 public string response_payload; 441 [CCode (cname="MAX_UPLOADS")] 442 public static int MAX_UPLOADS; 443 public signal void image_upload_progress (string a, double d); 444 public signal void image_upload_finished (string a, string? b); 445 public signal void image_upload_id_assigned (string file_path, int64 media_id); 446 public ComposeJob (Cb.UserStream user_stream, Rest.Proxy proxy, Rest.Proxy proxy2, GLib.Cancellable cancellable); 447 public void set_reply_id (int64 id); 448 public void set_quoted_tweet (Cb.Tweet t); 449 public void set_text (string s); 450 public void upload_image_async (string path, string uuid); 451 public void abort_image_upload (string uuid); 452 public async bool send_async (GLib.Cancellable c) throws GLib.Error; 453 // https://wiki.gnome.org/Projects/Vala/ManualBindings#Array_Lengths 454 public uint get_n_filepaths(); 455 public unowned string? get_filepath (uint pos); 456 } 457 458 [CCode (cprefix = "CbUserCompletionModel_", lower_case_cprefix = "cb_user_completion_model_", cheader_filename = 459 "CbUserCompletionModel.h")] 460 public class UserCompletionModel : GLib.Object, GLib.ListModel { 461 public UserCompletionModel (); 462 public void insert_infos (Cb.UserInfo[] infos); 463 public void insert_items (Cb.UserIdentity[] ids); 464 public void clear (); 465 } 466 467 [CCode (cprefix = "CbEmojiChooser_", lower_case_cprefix = "cb_emoji_chooser_", cheader_filename = 468 "CbEmojiChooser.h")] 469 public class EmojiChooser : Gtk.Box { 470 public EmojiChooser (); 471 public void populate (); 472 public bool try_init (); 473 public signal void emoji_picked (string emoji); 474 } 475} 476