Skip to content

Commit

Permalink
profile validation and code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
antenore committed Jan 20, 2016
1 parent 6cee49c commit 194cc9d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
3 changes: 1 addition & 2 deletions remmina/src/remmina_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "remmina_connection_window.h"
#include "remmina_about.h"
#include "remmina_plugin_manager.h"
#include "remmina_public.h"
#include "remmina_exec.h"
#include "remmina_survey.h"
#include "remmina_icon.h"
Expand Down Expand Up @@ -100,7 +99,7 @@ void remmina_exec_command(RemminaCommandType command, const gchar* data)
gtk_widget_show(widget);
/* Remmina survey reminder popup */
mainwindow = remmina_main_get_window();
if ( remmina_survey && remmina_public_count_profile() >= 1)
if ( remmina_survey && remmina_survey_valid_profile())
{
/* test if network is up and start survey */
remmina_survey_cb(GTK_WINDOW(mainwindow));
Expand Down
36 changes: 0 additions & 36 deletions remmina/src/remmina_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,39 +701,3 @@ void remmina_public_str_replace_in_place(gchar *string, const gchar *search, con
string = g_strdup(new_string);
return;
}
/* Get the number of remmina profiles counting how many .remmina file we have */
gint
remmina_public_count_profile()
{
TRACE_CALL("remmina_public_count_profile");

GDir *dir;
static gchar remdir[PATH_MAX];
GError *gerror = NULL;
gchar filename[PATH_MAX];
const gchar *dir_entry;
gint count_profile=0;

g_snprintf(remdir, sizeof(remdir), "%s/.%s", g_get_home_dir(), "remmina");
dir = g_dir_open(remdir, 0, &gerror);
if (gerror != NULL)
{
g_message("Cannot open %s, with error: %s", remdir, gerror->message);
g_error_free(gerror);
g_snprintf(remdir, sizeof(remdir),
"%s/%s", g_get_user_data_dir(), "remmina");
}else{

while ((dir_entry = g_dir_read_name(dir)) != NULL) {
/* Olny *.remmina files */
if (!g_str_has_suffix(dir_entry, ".remmina\0"))
continue;
g_snprintf(filename, PATH_MAX, "%s/%s", remdir, dir_entry);

if (filename != NULL)
count_profile++;
}
g_dir_close(dir);
}
return count_profile;
}
1 change: 0 additions & 1 deletion remmina/src/remmina_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,4 @@ gboolean remmina_public_resolution_validation_func(const gchar *new_str, gchar *
/* Replaces all occurences of search in a new copy of string by replacement
* and overwrites the original string */
void remmina_public_str_replace_in_place(gchar *string, const gchar *search, const gchar *replacement);
gint remmina_public_count_profile();
#endif /* __REMMINAPUBLIC_H__ */
37 changes: 37 additions & 0 deletions remmina/src/remmina_survey.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,43 @@ static const gchar *remmina_get_datadir()
return remdir;
}

/* At least one .remmina file */
gboolean remmina_survey_valid_profile()
{
TRACE_CALL("remmina_public_count_profile");

GDir *dir;
static gchar remdir[PATH_MAX];
GError *gerror = NULL;
gchar filename[PATH_MAX];
const gchar *dir_entry;
gint count_profile=0;
gint min_profiles=1; /* Use a constant */

g_snprintf(remdir, sizeof(remdir), "%s/.%s", g_get_home_dir(), "remmina");
dir = g_dir_open(remdir, 0, &gerror);
if (gerror != NULL)
{
g_message("Cannot open %s, with error: %s", remdir, gerror->message);
g_error_free(gerror);
g_snprintf(remdir, sizeof(remdir),
"%s/%s", g_get_user_data_dir(), "remmina");
}else{

while ((dir_entry = g_dir_read_name(dir)) != NULL) {
/* Olny *.remmina files */
if (!g_str_has_suffix(dir_entry, ".remmina\0"))
continue;
g_snprintf(filename, PATH_MAX, "%s/%s", remdir, dir_entry);

if (filename != NULL)
count_profile++;
}
g_dir_close(dir);
}
return (count_profile >= min_profiles);
}

/* Insert setting name and its count in an hashtable */
static void remmina_survey_ret_stat_from_setting(GHashTable *hash_table, gchar *name)
{
Expand Down
1 change: 1 addition & 0 deletions remmina/src/remmina_survey.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef struct _RemminaSurveyDialog

G_BEGIN_DECLS

gboolean remmina_survey_valid_profile();
void remmina_survey_on_startup(GtkWindow *parent);
gboolean remmina_survey_cb(gpointer data);
void remmina_survey_start();
Expand Down

0 comments on commit 194cc9d

Please sign in to comment.