From 9c21fb209a08d05da42af9b87123be10b17eaeeb Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 15 Jun 2008 21:44:45 -0500 Subject: [PATCH] Display more specific error messages when project open fails. --- Timeline/LASH.C | 2 +- Timeline/Project.C | 11 ++++++----- Timeline/Project.H | 9 ++++++++- Timeline/TLE.fl | 35 ++++++++++++++++++++++++----------- Timeline/main.C | 2 +- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Timeline/LASH.C b/Timeline/LASH.C index 3cfca47..dbcce00 100644 --- a/Timeline/LASH.C +++ b/Timeline/LASH.C @@ -107,7 +107,7 @@ LASH::handle_restore_file ( const char *path ) fclose( fp ); - return Project::open( project_path ); + return Project::open( project_path ) == 0; } void diff --git a/Timeline/Project.C b/Timeline/Project.C index 457a086..816e11e 100644 --- a/Timeline/Project.C +++ b/Timeline/Project.C @@ -209,11 +209,12 @@ Project::validate ( const char *name ) return r; } -bool +/** try to open project /name/. Returns 0 if sucsessful, an error code otherwise */ +int Project::open ( const char *name ) { if ( ! validate( name ) ) - return false; + return E_INVALID; close(); @@ -222,7 +223,7 @@ Project::open ( const char *name ) if ( ! get_lock( ".lock" ) ) { WARNING( "Could not open project: locked by another process!" ); - return false; + return Project::E_LOCKED; } if ( ! Loggable::open( "history" ) ) @@ -241,7 +242,7 @@ Project::open ( const char *name ) timeline->zoom_fit(); - return true; + return 0; } bool @@ -271,7 +272,7 @@ Project::create ( const char *name, const char *template_name ) /* TODO: copy template */ - if ( open( name ) ) + if ( open( name ) == 0 ) { write_info(); diff --git a/Timeline/Project.H b/Timeline/Project.H index 1aab871..359344d 100644 --- a/Timeline/Project.H +++ b/Timeline/Project.H @@ -33,13 +33,20 @@ class Project public: + enum + { + E_INVALID = -1, + E_LOCKED = -2, + E_PERM = -3, + }; + static bool write_info ( void ); static bool read_info ( void ); static const char *name ( void ) { return Project::_name; } static void set_name ( const char *name ); static bool close ( void ); static bool validate ( const char *name ); - static bool open ( const char *name ); + static int open ( const char *name ); static bool open ( void ) { return _is_open; } static bool create ( const char *name, const char *template_name ); diff --git a/Timeline/TLE.fl b/Timeline/TLE.fl index 9e7abae..a5985f7 100644 --- a/Timeline/TLE.fl +++ b/Timeline/TLE.fl @@ -160,10 +160,10 @@ Loggable::progress_callback( &TLE::progress_cb, this );} {} Function {make_window()} {open } { Fl_Window main_window { - label Timeline + label Timeline open xywh {174 117 1025 770} type Double resizable xclass Non_DAW visible } { - Fl_Menu_Bar menubar { + Fl_Menu_Bar menubar {open xywh {0 0 1024 25} } { Submenu {} { @@ -198,16 +198,29 @@ if ( ! name ) return; -if ( ! Project::validate( name ) ) -{ - fl_alert( "The path \\"%s\\"\\ndoes not refer to a valid Non-DAW project!", name ); -} -else if ( ! Project::open( name ) ) -{ - fl_alert( "Could not open \\"%s\\" as a Non-DAW project!", name ); +int r = Project::open( name ); +if ( r < 0 ) +{ + const char *s = ""; + + switch ( r ) + { + case Project::E_LOCKED: + s = "Locked by another process"; + break; + case Project::E_PERM: + s = "Access denied"; + break; + case Project::E_INVALID: + s = "Not a Non-DAW project"; + break; + } + + + fl_alert( "Could not open project \\"%s\\":\\n\\n\\t%s", name, s ); // we are in a somewhar ambiguous state now with no project open. -}} +}} selected xywh {10 10 40 25} } MenuItem {} { @@ -932,7 +945,7 @@ while ( window->shown() ) Function {make_window()} {open } { Fl_Window window { - label {Project info} open selected + label {Project info} open private xywh {649 226 520 625} type Double modal visible } { Fl_Value_Output {} { diff --git a/Timeline/main.C b/Timeline/main.C index 6cdd605..2cf95f0 100644 --- a/Timeline/main.C +++ b/Timeline/main.C @@ -140,7 +140,7 @@ main ( int argc, char **argv ) tle->run(); if ( argc > 1 ) - if ( ! Project::open( argv[ 1 ] ) ) + if ( Project::open( argv[ 1 ] ) != 0 ) FATAL( "Could not open project specified on command line" ); /* FIXME: open project in /tmp if none is given? */