~ubuntu-branches/ubuntu/trusty/unity-place-files/trusty

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-08-13 14:25:39 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20100813142539-s79xch3u5ec3vs1u
Tags: upstream-0.5.14
ImportĀ upstreamĀ versionĀ 0.5.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <string.h>
28
28
#include <zeitgeist.h>
29
29
#include <dee.h>
 
30
#include <gee.h>
 
31
#include <unity.h>
30
32
 
31
33
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
32
34
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
38
40
#define __g_list_free_g_object_unref0(var) ((var == NULL) ? NULL : (var = (_g_list_free_g_object_unref (var), NULL)))
39
41
typedef struct _UnityFilesPlaceUtilsListDirData UnityFilesPlaceUtilsListDirData;
40
42
 
 
43
#define UNITY_FILES_PLACE_TYPE_RESULTS_COLUMN (unity_files_place_results_column_get_type ())
 
44
 
41
45
struct _UnityFilesPlaceUtilsGetIconForUriAsyncData {
42
46
        int _state_;
43
47
        GAsyncResult* _res_;
57
61
        UNITY_FILES_PLACE_GROUP_RECENT,
58
62
        UNITY_FILES_PLACE_GROUP_DOWNLOADS,
59
63
        UNITY_FILES_PLACE_GROUP_FAVORITE_FOLDERS,
 
64
        UNITY_FILES_PLACE_GROUP_FILES,
60
65
        UNITY_FILES_PLACE_GROUP_TODAY,
61
66
        UNITY_FILES_PLACE_GROUP_YESTERDAY,
62
67
        UNITY_FILES_PLACE_GROUP_THIS_WEEK,
82
87
        GError * _inner_error_;
83
88
};
84
89
 
 
90
typedef enum  {
 
91
        UNITY_FILES_PLACE_RESULTS_COLUMN_URI = 0,
 
92
        UNITY_FILES_PLACE_RESULTS_COLUMN_ICON_HINT,
 
93
        UNITY_FILES_PLACE_RESULTS_COLUMN_GROUP_ID,
 
94
        UNITY_FILES_PLACE_RESULTS_COLUMN_MIMETYPE,
 
95
        UNITY_FILES_PLACE_RESULTS_COLUMN_DISPLAY_NAME,
 
96
        UNITY_FILES_PLACE_RESULTS_COLUMN_COMMENT
 
97
} UnityFilesPlaceResultsColumn;
 
98
 
85
99
 
86
100
 
87
101
#define UNITY_FILES_PLACE_UTILS_icon_attribs G_FILE_ATTRIBUTE_PREVIEW_ICON "," G_FILE_ATTRIBUTE_STANDARD_ICON "," G_FILE_ATTRIBUTE_THUMBNAIL_PATH
94
108
void unity_files_place_utils_get_icon_for_uri_async (const char* uri, const char* mimetype, GAsyncReadyCallback _callback_, gpointer _user_data_);
95
109
char* unity_files_place_utils_get_icon_for_uri_finish (GAsyncResult* _res_);
96
110
static gboolean unity_files_place_utils_get_icon_for_uri_async_co (UnityFilesPlaceUtilsGetIconForUriAsyncData* data);
 
111
gint unity_files_place_utils_cmp_file_info_by_mtime (GFileInfo* info1, GFileInfo* info2);
97
112
char* unity_files_place_utils_get_month_name (GDateMonth month);
98
113
GType unity_files_place_group_get_type (void) G_GNUC_CONST;
99
114
guint unity_files_place_utils_get_time_group (ZeitgeistEvent* event, DeeModel* groups_model);
104
119
void unity_files_place_utils_list_dir (GFile* folder, GAsyncReadyCallback _callback_, gpointer _user_data_);
105
120
GSList* unity_files_place_utils_list_dir_finish (GAsyncResult* _res_, GError** error);
106
121
static gboolean unity_files_place_utils_list_dir_co (UnityFilesPlaceUtilsListDirData* data);
 
122
GType unity_files_place_results_column_get_type (void) G_GNUC_CONST;
 
123
void unity_files_place_utils_apply_uri_filter (GeeSet* valid_uris, DeeResultSet* filter_set);
 
124
gboolean unity_files_place_utils_check_is_filter_search (UnityPlaceSearch* new_search, UnityPlaceSearch* old_search);
 
125
GeeSet* unity_files_place_utils_get_uri_set (ZeitgeistResultSet* results);
 
126
static int _vala_strcmp0 (const char * str1, const char * str2);
107
127
 
108
128
 
109
129
 
120
140
                info = g_file_query_info (f, UNITY_FILES_PLACE_UTILS_icon_attribs, G_FILE_QUERY_INFO_NONE, NULL, &_inner_error_);
121
141
                if (_inner_error_ != NULL) {
122
142
                        _g_object_unref0 (f);
123
 
                        goto __catch9_g_error;
 
143
                        goto __catch10_g_error;
124
144
                }
125
145
                result = unity_files_place_utils_check_icon_string (uri, mimetype, info);
126
146
                _g_object_unref0 (info);
127
147
                _g_object_unref0 (f);
128
148
                return result;
129
149
        }
130
 
        goto __finally9;
131
 
        __catch9_g_error:
 
150
        goto __finally10;
 
151
        __catch10_g_error:
132
152
        {
133
153
                GError * e;
134
154
                e = _inner_error_;
142
162
                        return result;
143
163
                }
144
164
        }
145
 
        __finally9:
 
165
        __finally10:
146
166
        {
147
167
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
148
168
                g_clear_error (&_inner_error_);
210
230
                        data->info = g_file_query_info_finish (data->f, data->_res_, &data->_inner_error_);
211
231
                        if (data->_inner_error_ != NULL) {
212
232
                                _g_object_unref0 (data->f);
213
 
                                goto __catch10_g_error;
 
233
                                goto __catch11_g_error;
214
234
                        }
215
235
                        data->result = unity_files_place_utils_check_icon_string (data->uri, data->mimetype, data->info);
216
236
                        _g_object_unref0 (data->info);
227
247
                        _g_object_unref0 (data->info);
228
248
                        _g_object_unref0 (data->f);
229
249
                }
230
 
                goto __finally10;
231
 
                __catch10_g_error:
 
250
                goto __finally11;
 
251
                __catch11_g_error:
232
252
                {
233
253
                        data->e = data->_inner_error_;
234
254
                        data->_inner_error_ = NULL;
250
270
                                _g_error_free0 (data->e);
251
271
                        }
252
272
                }
253
 
                __finally10:
 
273
                __finally11:
254
274
                {
255
275
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, data->_inner_error_->message, g_quark_to_string (data->_inner_error_->domain), data->_inner_error_->code);
256
276
                        g_clear_error (&data->_inner_error_);
302
322
}
303
323
 
304
324
 
 
325
gint unity_files_place_utils_cmp_file_info_by_mtime (GFileInfo* info1, GFileInfo* info2) {
 
326
        gint result = 0;
 
327
        GTimeVal tv1 = {0};
 
328
        GTimeVal tv2 = {0};
 
329
        glong cmp;
 
330
        gint _tmp0_ = 0;
 
331
        g_return_val_if_fail (info1 != NULL, 0);
 
332
        g_return_val_if_fail (info2 != NULL, 0);
 
333
        g_file_info_get_modification_time (info1, &tv1);
 
334
        g_file_info_get_modification_time (info2, &tv2);
 
335
        cmp = tv1.tv_sec - tv2.tv_sec;
 
336
        if (cmp < 0) {
 
337
                _tmp0_ = 1;
 
338
        } else {
 
339
                gint _tmp1_ = 0;
 
340
                if (cmp > 0) {
 
341
                        _tmp1_ = -1;
 
342
                } else {
 
343
                        _tmp1_ = 0;
 
344
                }
 
345
                _tmp0_ = _tmp1_;
 
346
        }
 
347
        result = _tmp0_;
 
348
        return result;
 
349
}
 
350
 
 
351
 
305
352
char* unity_files_place_utils_get_month_name (GDateMonth month) {
306
353
        char* result = NULL;
307
354
        switch (month) {
486
533
}
487
534
 
488
535
 
 
536
/**
 
537
     * Asynchrnously list the contents of a directory given by a path,
 
538
     * and return a list of FileInfos filled with the attributes specified
 
539
     * by Utils.all_attribs
 
540
     */
489
541
static gboolean unity_files_place_utils_list_dir_co (UnityFilesPlaceUtilsListDirData* data) {
490
542
        switch (data->_state_) {
491
543
                case 0:
583
635
}
584
636
 
585
637
 
 
638
void unity_files_place_utils_apply_uri_filter (GeeSet* valid_uris, DeeResultSet* filter_set) {
 
639
        DeeModel* model;
 
640
        guint n_removed;
 
641
        char* uri;
 
642
        g_return_if_fail (valid_uris != NULL);
 
643
        g_return_if_fail (filter_set != NULL);
 
644
        model = _g_object_ref0 (dee_result_set_get_model (filter_set));
 
645
        n_removed = (guint) 0;
 
646
        uri = NULL;
 
647
        {
 
648
                DeeResultSet* _row_it;
 
649
                DeeModelIter* row;
 
650
                _row_it = _vala_dee_result_set_iterator (filter_set);
 
651
                row = NULL;
 
652
                while (TRUE) {
 
653
                        char* _tmp0_;
 
654
                        if (!((row = _vala_dee_result_set_next_value (_row_it)) != NULL)) {
 
655
                                break;
 
656
                        }
 
657
                        uri = (_tmp0_ = g_strdup (dee_model_get_string (model, row, (guint) UNITY_FILES_PLACE_RESULTS_COLUMN_URI)), _g_free0 (uri), _tmp0_);
 
658
                        if (!gee_collection_contains ((GeeCollection*) valid_uris, uri)) {
 
659
                                dee_model_remove (model, row);
 
660
                                n_removed++;
 
661
                                g_debug ("utils.vala:230: Removed: %s", uri);
 
662
                        }
 
663
                }
 
664
                _g_object_unref0 (_row_it);
 
665
        }
 
666
        if (n_removed > 0) {
 
667
                g_debug ("utils.vala:235: Removed %u rows from result set", n_removed);
 
668
        }
 
669
        _g_free0 (uri);
 
670
        _g_object_unref0 (model);
 
671
}
 
672
 
 
673
 
 
674
gboolean unity_files_place_utils_check_is_filter_search (UnityPlaceSearch* new_search, UnityPlaceSearch* old_search) {
 
675
        gboolean result = FALSE;
 
676
        gboolean is_filter_search;
 
677
        g_return_val_if_fail (new_search != NULL, FALSE);
 
678
        is_filter_search = FALSE;
 
679
        if (old_search != NULL) {
 
680
                char* previous_search_string;
 
681
                gboolean _tmp0_ = FALSE;
 
682
                previous_search_string = unity_place_search_get_search_string (old_search);
 
683
                if (previous_search_string != NULL) {
 
684
                        _tmp0_ = _vala_strcmp0 (previous_search_string, "") != 0;
 
685
                } else {
 
686
                        _tmp0_ = FALSE;
 
687
                }
 
688
                if (_tmp0_) {
 
689
                        char* _tmp1_;
 
690
                        is_filter_search = g_str_has_prefix (_tmp1_ = unity_place_search_get_search_string (new_search), previous_search_string);
 
691
                        _g_free0 (_tmp1_);
 
692
                }
 
693
                _g_free0 (previous_search_string);
 
694
        }
 
695
        result = is_filter_search;
 
696
        return result;
 
697
}
 
698
 
 
699
 
 
700
GeeSet* unity_files_place_utils_get_uri_set (ZeitgeistResultSet* results) {
 
701
        GeeSet* result = NULL;
 
702
        GeeSet* uris;
 
703
        g_return_val_if_fail (results != NULL, NULL);
 
704
        uris = (GeeSet*) gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL);
 
705
        {
 
706
                ZeitgeistResultSet* _ev_it;
 
707
                ZeitgeistEvent* ev;
 
708
                _ev_it = _vala_zeitgeist_result_set_iterator (results);
 
709
                ev = NULL;
 
710
                while (TRUE) {
 
711
                        if (!((ev = _vala_zeitgeist_result_set_next_value (_ev_it)) != NULL)) {
 
712
                                break;
 
713
                        }
 
714
                        {
 
715
                                gint i;
 
716
                                i = 0;
 
717
                                {
 
718
                                        gboolean _tmp0_;
 
719
                                        _tmp0_ = TRUE;
 
720
                                        while (TRUE) {
 
721
                                                if (!_tmp0_) {
 
722
                                                        i++;
 
723
                                                }
 
724
                                                _tmp0_ = FALSE;
 
725
                                                if (!(i < zeitgeist_event_num_subjects (ev))) {
 
726
                                                        break;
 
727
                                                }
 
728
                                                gee_collection_add ((GeeCollection*) uris, zeitgeist_subject_get_uri (zeitgeist_event_get_subject (ev, i)));
 
729
                                        }
 
730
                                }
 
731
                        }
 
732
                }
 
733
                _g_object_unref0 (_ev_it);
 
734
        }
 
735
        result = uris;
 
736
        return result;
 
737
}
 
738
 
 
739
 
 
740
static int _vala_strcmp0 (const char * str1, const char * str2) {
 
741
        if (str1 == NULL) {
 
742
                return -(str1 != str2);
 
743
        }
 
744
        if (str2 == NULL) {
 
745
                return str1 != str2;
 
746
        }
 
747
        return strcmp (str1, str2);
 
748
}
 
749
 
 
750
 
586
751
 
587
752