notepad::CFileStore Class Reference

#include <notepad_filestore.h>

Collaboration diagram for notepad::CFileStore:
Collaboration graph
[legend]

Public Member Functions

 CFileStore ()
virtual ~CFileStore ()
np_result createFile (const gchar *filename)
np_result openFile (const gchar *filename)
void closeFile ()
np_result renameFile (const gchar *newfilename)
gchar * getFilename (void)
erMetadb getFile (void)
gchar * getFileNameDirPart (void)
gchar * getFileNameFilePart (void)
gchar * getFileNameFilePartNoExt (void)
gint get_last_read_location (void)
 Load last read location from meta database.
gboolean set_last_read_location (gint location)

Detailed Description

Definition at line 41 of file notepad_filestore.h.


Constructor & Destructor Documentation

notepad::CFileStore::CFileStore (  ) 

Definition at line 50 of file notepad_filestore.cpp.

References LOGPRINTF.

00052         :
00053             m_db(0),
00054             m_dbfilename(0)
00055     {
00056         LOGPRINTF("entry");
00057         LOGPRINTF("exit");
    }

notepad::CFileStore::~CFileStore (  )  [virtual]

Definition at line 59 of file notepad_filestore.cpp.

References LOGPRINTF.

00060     {
00061         LOGPRINTF("entry");
00062         closeDatabase();
00063         LOGPRINTF("exit");
00064     }


Member Function Documentation

void notepad::CFileStore::closeFile (  ) 

Definition at line 295 of file notepad_filestore.cpp.

Referenced by notepad::CNotepadDoc::close().

00296     {
00297         return closeDatabase();
00298     }

Here is the caller graph for this function:

np_result notepad::CFileStore::createFile ( const gchar *  filename  ) 

Definition at line 215 of file notepad_filestore.cpp.

References notepad::ipc_get_mountpoint(), LOGPRINTF, NOTE_DIR, NOTE_EXTENSION, notepad::NP_OK, and WARNPRINTF.

Referenced by notepad::CNotepadDoc::create().

00216     {
00217         LOGPRINTF("filename='%s'", filename ? filename : "NULL");
00218 
00219         g_assert(m_dbfilename == 0);
00220         g_assert(m_db == 0);
00221 
00222         // determine dir + filename
00223         gchar* dir = 0;
00224         gchar* file = 0;
00225         if (  (filename != 0) && (filename[0] != '\0'))
00226         {
00227             dir = g_path_get_dirname(filename);
00228             file = g_path_get_basename(filename);
00229         }
00230         else 
00231         {
00232             dir = g_strdup_printf("%s/%s", ipc_get_mountpoint(), NOTE_DIR); 
00233             file = generateNewFilename();
00234         }
00235 
00236         gchar* title = 0;
00237         gchar* iter = g_strrstr(file, NOTE_EXTENSION);
00238         if ( iter == 0 ) // no needle found in the haystack
00239         {
00240             title =  g_strdup(file);
00241         }
00242         else
00243         {
00244             title =  g_strndup(file, (iter - file));
00245         }
00246 
00247         np_result result = createDatabase(dir, file, title);
00248         if (result == NP_OK)
00249         {
00250             m_dbfilename = g_strdup_printf("%s/%s", dir, file); 
00251         }
00252         else
00253         {
00254             WARNPRINTF("failed to create");
00255         }
00256 
00257         g_free(dir);
00258         g_free(file);
00259         g_free(title);
00260 
00261         LOGPRINTF("exit");
00262         return result;
00263     }

Here is the call graph for this function:

Here is the caller graph for this function:

gint notepad::CFileStore::get_last_read_location ( void   ) 

Load last read location from meta database.

Definition at line 532 of file notepad_filestore.cpp.

References LOGPRINTF, and notepad::SCRIBBLE_LAST_READ_LOCATION.

Referenced by notepad::CNotepadDoc::get_last_read().

00533     {
00534         gchar* location = 0;
00535         gboolean result = load_string (SCRIBBLE_LAST_READ_LOCATION, &location);
00536         gint last_read = 0;
00537         if ( ! result )
00538         {
00539             last_read = -1;
00540         }
00541         else if (sscanf( location, "%d", &last_read ) < 0)
00542         {
00543             last_read = -1;
00544         }
00545         g_free(location);
00546         LOGPRINTF( "get_last_read_location -- last_read = %d", last_read);
00547         return last_read;
00548     }

Here is the caller graph for this function:

erMetadb notepad::CFileStore::getFile ( void   ) 

Definition at line 369 of file notepad_filestore.cpp.

Referenced by notepad::CNotepadDoc::create(), and notepad::CNotepadDoc::open().

00370     {
00371         return m_db;
00372     }

Here is the caller graph for this function:

gchar * notepad::CFileStore::getFilename ( void   ) 

Definition at line 363 of file notepad_filestore.cpp.

Referenced by notepad::CNotepadDoc::get_full_filename(), notepad::CNotepadWindow::getFilename(), and notepad::CNotepadDoc::rename().

00364     {
00365         // CRASHES if run after constructor!!
00366         return m_dbfilename;
00367     }

Here is the caller graph for this function:

gchar * notepad::CFileStore::getFileNameDirPart ( void   ) 

Definition at line 410 of file notepad_filestore.cpp.

Referenced by renameFile().

00411     {
00412         g_assert( m_dbfilename != 0);
00413         return g_path_get_dirname(m_dbfilename);
00414     }

Here is the caller graph for this function:

gchar * notepad::CFileStore::getFileNameFilePart ( void   ) 

Definition at line 417 of file notepad_filestore.cpp.

Referenced by renameFile().

00418     {
00419         g_assert( m_dbfilename != 0);
00420         return g_path_get_basename(m_dbfilename);
00421     }

Here is the caller graph for this function:

gchar * notepad::CFileStore::getFileNameFilePartNoExt ( void   ) 

Definition at line 424 of file notepad_filestore.cpp.

Referenced by notepad::CNotepadDoc::get_filename_without_dir_and_ext(), notepad::CNotepadWindow::getLabel(), and notepad::CNotepadDoc::rename().

00425     {
00426         g_assert( m_dbfilename != 0);
00427         return noExt(m_dbfilename);
00428     }

Here is the caller graph for this function:

np_result notepad::CFileStore::openFile ( const gchar *  filename  ) 

Definition at line 265 of file notepad_filestore.cpp.

References LOGPRINTF, notepad::NP_NO_FILENAME, notepad::NP_OK, and WARNPRINTF.

Referenced by notepad::CNotepadDoc::open().

00266     {
00267         LOGPRINTF("entry");
00268 
00269         g_assert( m_dbfilename == 0);
00270         g_assert( m_db == 0);
00271 
00272         // input check
00273         g_return_val_if_fail((filename != 0) && (filename[0] != '\0'), NP_NO_FILENAME);
00274 
00275         gchar* directory = g_path_get_dirname(filename);
00276         gchar* file = g_path_get_basename(filename);
00277         np_result result = openDatabase(directory, file);
00278 
00279         if ( result == NP_OK)
00280         {
00281             m_dbfilename = g_strdup(filename);
00282         }
00283         else
00284         {
00285             WARNPRINTF("failed to open");
00286         }
00287 
00288         g_free(directory);
00289         g_free(file);
00290 
00291         LOGPRINTF("exit");
00292         return result;
00293     }

Here is the caller graph for this function:

np_result notepad::CFileStore::renameFile ( const gchar *  newfilename  ) 

Definition at line 300 of file notepad_filestore.cpp.

References getFileNameDirPart(), getFileNameFilePart(), LOGPRINTF, NOTE_EXTENSION, notepad::NP_FILE_EXISTS, notepad::NP_NO_FILENAME, and notepad::NP_OK.

Referenced by notepad::CNotepadDoc::rename().

00301     {
00302         LOGPRINTF("entry");
00303         np_result result = NP_OK;
00304 
00305         g_assert( m_dbfilename != 0);
00306         g_assert( m_db != 0);
00307 
00308         // input check
00309         g_return_val_if_fail((newshortfilename != 0) && (newshortfilename[0] != '\0'), NP_NO_FILENAME);
00310 
00311         // assemble filenames 
00312         gchar* dir = getFileNameDirPart();
00313         gchar* newfilename = 0;
00314         int len = strlen(newshortfilename) - strlen(NOTE_EXTENSION);
00315         if (0 == g_strcmp0(newshortfilename + len, NOTE_EXTENSION))
00316         {
00317             g_assert(len > 0);
00318             newfilename = g_strdup_printf("%s/%s", dir, newshortfilename); 
00319         }
00320         else
00321         {
00322             newfilename = g_strdup_printf("%s/%s%s", dir, newshortfilename, NOTE_EXTENSION); 
00323         }
00324         LOGPRINTF("oldfilename %s, newfilename %s", m_dbfilename, newfilename);
00325 
00326         // test if new == old;
00327         if (0 == g_strcmp0(m_dbfilename, newfilename))
00328         {
00329             LOGPRINTF("save as same filename");
00330             result = NP_OK;
00331         }
00332         else
00333         {
00334             // test if file already exists
00335             if (g_file_test(newfilename, G_FILE_TEST_EXISTS))
00336                 result = NP_FILE_EXISTS;
00337 
00338             if (result != NP_FILE_EXISTS)
00339             {
00340                 gchar* srcfile  = getFileNameFilePart();
00341                 gchar* destfile = g_path_get_basename(newfilename);
00342 
00343                 // create local db with filename
00344                 result = renameDatabase(dir, srcfile, destfile); 
00345                 if (result == NP_OK)
00346                 {
00347                     // rename succeeded, store filename
00348                     g_free(m_dbfilename);
00349                     m_dbfilename = g_strdup(newfilename);
00350                 }
00351                 g_free(srcfile);
00352                 g_free(destfile);
00353             }
00354         }
00355 
00356         g_free(dir);
00357         g_free(newfilename);
00358 
00359         LOGPRINTF("FUNCTION EXIT");
00360         return result; 
00361     }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean notepad::CFileStore::set_last_read_location ( gint  location  ) 

Definition at line 550 of file notepad_filestore.cpp.

References LOGPRINTF, and notepad::SCRIBBLE_LAST_READ_LOCATION.

Referenced by notepad::CNotepadDoc::set_last_read().

00551     {
00552         LOGPRINTF( "set_last_read_location -- last_read = %d", location);
00553         gboolean result = FALSE;
00554         gchar* my_location = g_strdup_printf("%d", location);
00555         result = save_string( SCRIBBLE_LAST_READ_LOCATION, my_location);
00556         g_free(my_location);
00557         return result; 
00558     }

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208