Only enable the New Entry button when in a valid workspace
This commit is contained in:
		
							parent
							
								
									75155331ea
								
							
						
					
					
						commit
						3ba42da401
					
				@ -1050,6 +1050,20 @@ static void mainWindow_show_error(struct mainWindow *mainWindow, gchar *text)
 | 
			
		||||
	gtk_widget_destroy(dialog);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void mainWindow_show_info(struct mainWindow *mainWindow, gchar *text)
 | 
			
		||||
{
 | 
			
		||||
	GtkWidget *dialog;
 | 
			
		||||
 | 
			
		||||
	dialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow->mainWindow),
 | 
			
		||||
					GTK_DIALOG_DESTROY_WITH_PARENT,
 | 
			
		||||
					GTK_MESSAGE_INFO,
 | 
			
		||||
					GTK_BUTTONS_CLOSE,
 | 
			
		||||
					"%s",
 | 
			
		||||
					text);
 | 
			
		||||
	gtk_dialog_run(GTK_DIALOG(dialog));
 | 
			
		||||
	gtk_widget_destroy(dialog);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gboolean gpg_enabled)
 | 
			
		||||
{
 | 
			
		||||
	struct mdiary_scanner *mdiary_scanner;
 | 
			
		||||
@ -1086,8 +1100,25 @@ void mainWindow_switch_workspace(struct mainWindow *mainWindow, gchar *path, gbo
 | 
			
		||||
			g_free(temp);
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		gtk_header_bar_set_subtitle(GTK_HEADER_BAR(mainWindow->headerBar), "No workspace opened.");
 | 
			
		||||
		mainWindow_show_error(mainWindow, "Could not open workspace or no entries were found in it.");
 | 
			
		||||
		if (mdiary_scanner->error_code & MDS_ERROR_GPG) {
 | 
			
		||||
			NULL; /* Handled in scanner */
 | 
			
		||||
		} else if (mdiary_scanner->error_code == 0) {
 | 
			
		||||
			mainWindow_show_info(mainWindow, "This workspace is empty. Use the New Entry button to create the first entry.");
 | 
			
		||||
		} else {
 | 
			
		||||
			mainWindow_show_error(mainWindow, "Could not open workspace. Please choose a different directory.");
 | 
			
		||||
			g_free(mainWindow->currentWorkspaceUrl);
 | 
			
		||||
			mainWindow->currentWorkspaceUrl = NULL;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (mainWindow->currentWorkspaceUrl) {
 | 
			
		||||
		gtk_header_bar_set_subtitle(GTK_HEADER_BAR(mainWindow->headerBar),
 | 
			
		||||
					    mainWindow->currentWorkspaceUrl);
 | 
			
		||||
		gtk_widget_set_sensitive(mainWindow->buttonNew, 1);
 | 
			
		||||
	} else {
 | 
			
		||||
		gtk_header_bar_set_subtitle(GTK_HEADER_BAR(mainWindow->headerBar),
 | 
			
		||||
					    "No workspace opened.");
 | 
			
		||||
		gtk_widget_set_sensitive(mainWindow->buttonNew, 0);
 | 
			
		||||
	}
 | 
			
		||||
	mdiary_scanner_free(mdiary_scanner);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -381,6 +381,7 @@ static void mdiary_add_gpg_to_store(struct mdiary_scanner *mdiary_scanner,
 | 
			
		||||
		mdiary_add_file_to_store(mdiary_scanner, filename, cmd_stdout, entryListStore, autoCompletion);
 | 
			
		||||
	} else {
 | 
			
		||||
		mdiary_scanner->entries_failed++;
 | 
			
		||||
		mdiary_scanner->error_code |= MDS_ERROR_GPG;
 | 
			
		||||
		g_warning("GPG: Decryption of message failed!\n"
 | 
			
		||||
			  "---------- SNIP ----------\n"
 | 
			
		||||
			  "%s"
 | 
			
		||||
@ -407,6 +408,7 @@ static void mdiary_recurse_and_collect(struct mdiary_scanner *mdiary_scanner,
 | 
			
		||||
 | 
			
		||||
	if (!dir) {
 | 
			
		||||
		g_print("Could not open base directory.\n");
 | 
			
		||||
		mdiary_scanner->error_code |= MDS_ERROR_BASE_DIR;
 | 
			
		||||
	} else {
 | 
			
		||||
		while (dirname = (gchar *)g_dir_read_name(dir)) {
 | 
			
		||||
			fullPath = g_strdup_printf("%s/%s", base_dir, dirname);
 | 
			
		||||
@ -455,6 +457,7 @@ struct mdiary_scanner *mdiary_scanner_new(gboolean gpg_enabled)
 | 
			
		||||
		mdiary_scanner->gpg_enabled       = gpg_enabled;
 | 
			
		||||
		mdiary_scanner->entries_failed    = 0;
 | 
			
		||||
		mdiary_scanner->entries_encrypted = 0;
 | 
			
		||||
		mdiary_scanner->error_code        = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return mdiary_scanner;
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,9 @@
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#define MDS_ERROR_BASE_DIR 1
 | 
			
		||||
#define MDS_ERROR_GPG 2
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
	COL_TITLE = 0,  /* Title of the entry */
 | 
			
		||||
	COL_DATE_TEXT,	/* Textual representation of the date (auto generated) */
 | 
			
		||||
@ -24,6 +27,7 @@ struct mdiary_scanner {
 | 
			
		||||
	gint entries_added;
 | 
			
		||||
	gint entries_encrypted;
 | 
			
		||||
	gint entries_failed;
 | 
			
		||||
	gint error_code;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct mdiary_scanner *mdiary_scanner_new(gboolean gpg_enabled);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user