void syl_save_all_state(void) { folder_write_list(); prefs_common_write_config(); filter_write_config(); account_write_config_all(); }
void rssyl_new_folder_cb(GtkAction *action, gpointer data) { FolderView *folderview = (FolderView*)data; FolderItem *item; FolderItem *new_item; gchar *new_folder, *p, *tmp; gint i = 1; if (!folderview->selected) return; item = folderview_get_selected_item(folderview); g_return_if_fail(item != NULL); g_return_if_fail(item->folder != NULL); new_folder = input_dialog(_("New folder"), _("Input the name of new folder:"), _("NewFolder")); if (!new_folder) return; p = strchr(new_folder, G_DIR_SEPARATOR); if (p) { alertpanel_error(_("'%c' can't be used in folder name."), G_DIR_SEPARATOR); g_free(new_folder); return; } if (!folder_local_name_ok(new_folder)) { g_free(new_folder); return; } /* Find an unused name for new folder */ /* TODO: Perhaps stop after X attempts? */ tmp = g_strdup(new_folder); while (folder_find_child_item_by_name(item, tmp)) { debug_print("RSSyl: Folder '%s' already exists, trying another name\n", new_folder); g_free(tmp); tmp = g_strdup_printf("%s__%d", new_folder, ++i); } g_free(new_folder); new_folder = tmp; new_item = folder_create_folder(item, new_folder); if (!new_item) { alertpanel_error(_("Can't create the folder '%s'."), new_folder); g_free(new_folder); return; } g_free(new_folder); folder_write_list(); }
static void unsubscribe_newsgroup_cb(GtkAction *action, gpointer data) { FolderView *folderview = (FolderView *)data; FolderItem *item; gchar *name; gchar *message; gchar *old_id; AlertValue avalue; MainWindow *mainwin = mainwindow_get_mainwindow(); if (!folderview->selected) return; item = folderview_get_selected_item(folderview); cm_return_if_fail(item != NULL); if (mainwin->lock_count || news_folder_locked(item->folder)) return; cm_return_if_fail(item->folder != NULL); cm_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS); cm_return_if_fail(item->folder->account != NULL); old_id = folder_item_get_identifier(item); name = trim_string(item->path, 32); message = g_strdup_printf(_("Really unsubscribe newsgroup '%s'?"), name); avalue = alertpanel_full(_("Unsubscribe newsgroup"), message, GTK_STOCK_CANCEL, _("_Unsubscribe"), NULL, ALERTFOCUS_FIRST, FALSE, NULL, ALERT_WARNING); g_free(message); g_free(name); if (avalue != G_ALERTALTERNATE) return; if (item == folderview_get_opened_item(folderview)) { summary_clear_all(folderview->summaryview); folderview_close_opened(folderview, TRUE); } if(item->folder->klass->remove_folder(item->folder, item) < 0) { folder_item_scan(item); alertpanel_error(_("Can't remove the folder '%s'."), name); g_free(old_id); return; } folder_write_list(); prefs_filtering_delete_path(old_id); g_free(old_id); }
void rssyl_update_format() { RUpdateFormatCtx *ctx = NULL; GSList *oldfeeds; gchar *old_feeds_xml = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RSSYL_DIR, G_DIR_SEPARATOR_S, "feeds.xml", NULL); if (!g_file_test(old_feeds_xml, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { g_free(old_feeds_xml); return; } debug_print("RSSyl: Old format found, updating.\n"); oldfeeds = rssyl_old_feed_metadata_parse(old_feeds_xml); /* We find all rssyl root folders and perform magic on each */ ctx = g_new0(RUpdateFormatCtx, 1); ctx->o_prev = NULL; ctx->o_parent = NULL; ctx->n_prev = NULL; ctx->n_parent = NULL; ctx->n_first = NULL; ctx->oldfeeds = oldfeeds; ctx->oldroots = NULL; ctx->reached_first_new = FALSE; folder_item_update_freeze(); /* Go through all RSSyl folders, making new copies */ folder_func_to_all_folders((FolderItemFunc)rssyl_update_format_func, ctx); g_slist_foreach(ctx->oldroots, _delete_old_roots_func, NULL); g_slist_free(ctx->oldroots); prefs_matcher_write_config(); folder_write_list(); folder_item_update_thaw(); g_free(ctx); g_remove(old_feeds_xml); g_free(old_feeds_xml); }
gboolean rssyl_subscribe(FolderItem *parent, const gchar *url, gboolean verbose) { gchar *myurl = NULL, *tmpname = NULL, *tmpname2 = NULL; RFetchCtx *ctx; FolderItem *new_item; RFolderItem *ritem; gint i = 1; RSubCtx *sctx; gboolean edit_properties = FALSE; gchar *official_title = NULL; g_return_val_if_fail(parent != NULL, FALSE); g_return_val_if_fail(url != NULL, FALSE); log_print(LOG_PROTOCOL, RSSYL_LOG_SUBSCRIBING, url); myurl = my_normalize_url(url); /* Fetch the feed. */ ctx = rssyl_prep_fetchctx_from_url(myurl); g_free(myurl); g_return_val_if_fail(ctx != NULL, FALSE); rssyl_fetch_feed(ctx, verbose); debug_print("RSSyl: fetch success == %s\n", ctx->success ? "TRUE" : "FALSE"); if (!ctx->success) { /* User notification was already handled inside rssyl_fetch_feed(), * let's just return quietly. */ feed_free(ctx->feed); g_free(ctx->error); g_free(ctx); return FALSE; } if (verbose) { sctx = g_new0(RSubCtx, 1); sctx->feed = ctx->feed; sctx->edit_properties = FALSE; debug_print("RSSyl: Calling subscribe dialog routine...\n"); rssyl_subscribe_dialog(sctx); if (sctx->feed == NULL) { debug_print("RSSyl: User cancelled subscribe.\n"); g_free(sctx); return FALSE; } edit_properties = sctx->edit_properties; if (sctx->official_title != NULL) { debug_print("RSSyl: custom official title\n"); official_title = g_strdup(sctx->official_title); } if (sctx->edit_properties) debug_print("RSSyl: User wants to edit properties of the new feed.\n"); else debug_print("RSSyl: User does not want to edit properties of the new feed.\n"); g_free(sctx->official_title); g_free(sctx); } /* OK, feed is succesfully fetched and correct, let's add it to CM. */ /* Create a folder for it. */ tmpname = rssyl_format_string(ctx->feed->title, TRUE, TRUE); tmpname2 = g_strdup(tmpname); #ifdef G_OS_WIN32 /* Windows does not allow its filenames to start or end with a dot, * or to end with a space. */ if (tmpname2[0] == '.') tmpname2[0] = '_'; if (tmpname2[strlen(tmpname2) - 1] == '.') tmpname2[strlen(tmpname2) - 1] = '_'; if (tmpname2[strlen(tmpname2) - 1] == ' ') tmpname2[strlen(tmpname2) - 1] = '_'; #endif while (folder_find_child_item_by_name(parent, tmpname2) != 0 && i < 20) { debug_print("RSSyl: Folder '%s' already exists, trying another name\n", tmpname2); g_free(tmpname2); tmpname2 = g_strdup_printf("%s__%d", tmpname, ++i); } /* TODO: handle cases where i reaches 20 */ folder_item_update_freeze(); new_item = folder_create_folder(parent, tmpname2); g_free(tmpname); g_free(tmpname2); if (!new_item) { if (verbose) alertpanel_error(_("Couldn't create folder for new feed '%s'."), myurl); feed_free(ctx->feed); g_free(ctx->error); g_free(ctx); g_free(myurl); return FALSE; } debug_print("RSSyl: Adding '%s'\n", ctx->feed->url); ritem = (RFolderItem *)new_item; ritem->url = g_strdup(ctx->feed->url); if (official_title != NULL) { debug_print("RSSyl: storing official feed title '%s'\n", official_title); ritem->official_title = official_title; } if (feed_n_items(ctx->feed) > 0) feed_foreach_item(ctx->feed, rssyl_subscribe_foreach_func, (gpointer)ritem); folder_item_scan(new_item); folder_write_list(); if (edit_properties) rssyl_gtk_prop(ritem); folder_item_update_thaw(); return TRUE; }
static void rssyl_update_format_func(FolderItem *item, gpointer data) { RFolderItem *ritem; RUpdateFormatCtx *ctx = (RUpdateFormatCtx *)data; Folder *f = NULL; FolderItem *new_item = NULL; gchar *name; OldRFeed *of; if( !IS_RSSYL_FOLDER_ITEM(item) ) return; /* Do not do anything once we reached first new folder * (which we created earlier in this process) */ if( ctx->reached_first_new ) return; if( item->folder == ctx->n_first ) { ctx->reached_first_new = TRUE; debug_print("RSSyl: (FORMAT) reached first new folder\n"); return; } debug_print("RSSyl: (FORMAT) item '%s'\n", item->name); if( folder_item_parent(item) == NULL ) { /* Root rssyl folder */ ctx->oldroots = g_slist_prepend(ctx->oldroots, item); /* Create its counterpart */ name = rssyl_strreplace(folder_item_get_name(item), " (RSSyl)", ""); debug_print("RSSyl: (FORMAT) adding new root folder '%s'\n", name); f = folder_new(rssyl_folder_get_class(), name, NULL); g_free(name); g_return_if_fail(f != NULL); folder_add(f); folder_write_list(); new_item = FOLDER_ITEM(f->node->data); /* If user has more than one old rssyl foldertrees, keep the n_first * pointer at the beginning of first one. */ if (ctx->n_first == NULL) ctx->n_first = f; ctx->n_parent = new_item; } else { /* Non-root folder */ if (folder_item_parent(item) == ctx->o_prev) { /* We went one step deeper in folder hierarchy, adjust pointers * to parents */ ctx->o_parent = ctx->o_prev; ctx->n_parent = ctx->n_prev; } else if (folder_item_parent(item) != ctx->o_parent) { /* We are not in same folder anymore, which can only mean we have * moved up in the hierarchy. Find a correct parent */ while (folder_item_parent(item) != ctx->o_parent) { ctx->o_parent = folder_item_parent(ctx->o_parent); ctx->n_parent = folder_item_parent(ctx->n_parent); if (ctx->o_parent == NULL) { /* This shouldn't happen, unless we are magically moved to a * completely different folder structure */ debug_print("RSSyl: MISHAP WHILE UPGRADING STORAGE FORMAT: couldn't find folder parent\n"); alertpanel_error(_("Internal problem while upgrading storage format. This should not happen. Please report this, with debug output attached.\n")); return; } } } else { /* We have remained in the same subfolder, nothing to do here */ } debug_print("RSSyl: (FORMAT) adding folder '%s'\n", item->name); new_item = folder_create_folder(ctx->n_parent, item->name); if (new_item == NULL) { debug_print("RSSyl: (FORMAT) couldn't add folder '%s', skipping it\n", item->name); return; } of = rssyl_old_feed_get_by_name(ctx->oldfeeds, item->name); if (of != NULL && of->url != NULL) { /* Folder with an actual subscribed feed */ debug_print("RSSyl: (FORMAT) making '%s' a feed with URL '%s'\n", item->name, of->url); ritem = (RFolderItem *)new_item; ritem->url = g_strdup(of->url); rssyl_feed_start_refresh_timeout(ritem); ritem->official_title = g_strdup(of->official_name); ritem->default_refresh_interval = (of->default_refresh_interval != 0 ? TRUE : FALSE); ritem->refresh_interval = of->refresh_interval; ritem->keep_old = (of->expired_num > -1 ? TRUE : FALSE); ritem->fetch_comments = (of->fetch_comments != 0 ? TRUE : FALSE); ritem->fetch_comments_max_age = of->fetch_comments_for; ritem->silent_update = of->silent_update; ritem->ssl_verify_peer = of->ssl_verify_peer; folder_item_prefs_copy_prefs(item, &ritem->item); } rssyl_update_format_move_contents(item, new_item); /* destroy the new folder's cache so we'll re-read the migrated one */ if (new_item->cache) { msgcache_destroy(new_item->cache); new_item->cache = NULL; } /* Store folderlist with the new folder */ folder_item_scan(new_item); folder_write_list(); } ctx->o_prev = item; ctx->n_prev = new_item; }
static void subscribe_newsgroup_cb(GtkAction *action, gpointer data) { FolderView *folderview = (FolderView *)data; Folder *folder; FolderItem *item; FolderItem *rootitem; FolderItem *newitem; GSList *new_subscr; GSList *cur; GNode *gnode; MainWindow *mainwin = mainwindow_get_mainwindow(); if ((item = folderview_get_selected_item(folderview)) == NULL) return; if (mainwin->lock_count || news_folder_locked(item->folder)) return; folder = item->folder; cm_return_if_fail(folder != NULL); cm_return_if_fail(FOLDER_TYPE(folder) == F_NEWS); cm_return_if_fail(folder->account != NULL); if ((rootitem = folder_item_parent(item)) == NULL) rootitem = item; new_subscr = grouplist_dialog(folder); /* remove unsubscribed newsgroups */ for (gnode = folder->node->children; gnode != NULL; ) { GNode *next = gnode->next; item = FOLDER_ITEM(gnode->data); if (g_slist_find_custom(new_subscr, item->path, (GCompareFunc)g_ascii_strcasecmp) != NULL) { gnode = next; continue; } if (folderview_get_opened_item(folderview) == item) { summary_clear_all(folderview->summaryview); folderview_close_opened(folderview, TRUE); } folderview_remove_item(folderview, item); folder_item_remove(item); gnode = next; } folderview_freeze(folderview); /* add subscribed newsgroups */ for (cur = new_subscr; cur != NULL; cur = cur->next) { gchar *name = (gchar *)cur->data; FolderUpdateData hookdata; if (news_find_child_item(rootitem, name) != NULL) continue; newitem = folder_item_new(folder, name, name); folder_item_append(rootitem, newitem); hookdata.folder = newitem->folder; hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_ADD_FOLDERITEM; hookdata.item = newitem; hookdata.item2 = NULL; hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata); } folderview_thaw(folderview); slist_free_strings_full(new_subscr); folder_write_list(); }