examples/ForumNokia/DBMS/src/DBMSAppui.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 #include <avkon.hrh>
00006 #include <badesca.h>
00007 #include <bautils.h>
00008 #include <eikmenup.h>
00009 #include <eikapp.h>
00010 #include <aknnotewrappers.h> // CAknInformationNote
00011 #include <aknquerydialog.h>
00012 #include "DBMSAppUi.h"
00013 #include "DBMSAppView.h"
00014 #include "DBMSListboxView.h"
00015 #include "DBMSEditorView.h"
00016 #include "DBMS.hrh"
00017 #include <DBMS.rsg>  // R_MAIN_MENU
00018 
00019 #define KEnableSkinFlag 0x1000
00020 
00021 // Implementation constants
00022 const TInt KArrayGranularity = 5;
00023 
00024 //Text constants
00025 _LIT(KCDrive, "C:");
00026 
00027 // ---------------------------------------------------------------------------
00028 // CDBMSAppUi::ConstructL()
00029 //
00030 // Perform second phase construction. This is allowed to leave.
00031 // ---------------------------------------------------------------------------
00032 //
00033 void CDBMSAppUi::ConstructL()
00034     {
00035         BaseConstructL(EAknEnableSkin);
00036 
00037     iCurrentView = ENone;
00038 
00039     ChangeViewL(EMainView);
00040 
00041         iDatabaseFile = DatabaseDriveAndPathL();
00042 
00043     iDatabaseFile.Append(KDatabaseFile);
00044     }
00045 
00046 
00047 // ---------------------------------------------------------------------------
00048 // CDBMSAppUi::CDBMSAppUi()
00049 //
00050 // Constructor of the AppUi. This may not leave.
00051 // ---------------------------------------------------------------------------
00052 //
00053 CDBMSAppUi::CDBMSAppUi() : iAppView(NULL), iListboxView(NULL),
00054     iBookEditorView(NULL), iBookDb(NULL)
00055     {
00056     }
00057 
00058 
00059 // ---------------------------------------------------------------------------
00060 // CDBMSAppUi::~CDBMSAppUi()
00061 //
00062 // Destructor. Release reserved resources
00063 // ---------------------------------------------------------------------------
00064 //
00065 CDBMSAppUi::~CDBMSAppUi()
00066     {
00067     if (iAppView)
00068         {
00069         if(iCurrentView == EMainView)
00070             iEikonEnv->RemoveFromStack(iAppView);
00071         delete iAppView;
00072         iAppView = NULL;
00073         }
00074 
00075     if (iListboxView)
00076         {
00077         if(iCurrentView == EListView || iCurrentView == EColumnsView)
00078             iEikonEnv->RemoveFromStack(iListboxView);
00079         delete iListboxView;
00080         iListboxView = NULL;
00081         }
00082 
00083     if (iBookEditorView)
00084         {
00085         if(iCurrentView == EEditorView)
00086             iEikonEnv->RemoveFromStack(iBookEditorView);
00087         delete iBookEditorView;
00088         iBookEditorView = NULL;
00089         }
00090 
00091     if(iBookDb) // Just in case
00092         {
00093         iBookDb->Close();
00094         delete iBookDb;
00095         iBookDb = NULL;
00096         }
00097     }
00098 
00099 
00100 // ---------------------------------------------------------------------------
00101 // CDBMSAppUi::ChangeView()
00102 //
00103 // Switch view.
00104 // ---------------------------------------------------------------------------
00105 //
00106 void CDBMSAppUi::ChangeViewL(TViewId aNewView)
00107     {
00108 
00109     if(aNewView == iCurrentView)
00110         return;
00111 
00112     // Delete previous view (window owning control)
00113     switch(iCurrentView)
00114         {
00115         case EMainView:
00116             RemoveFromStack(iAppView);
00117             delete iAppView;
00118             iAppView = NULL;
00119             break;
00120 
00121         case EListView:
00122             RemoveFromStack(iListboxView);
00123             delete iListboxView;
00124             iListboxView = NULL;
00125             break;
00126 
00127         case EColumnsView:
00128             RemoveFromStack(iListboxView);
00129             delete iListboxView;
00130             iListboxView = NULL;
00131             break;
00132 
00133         case EEditorView:
00134             RemoveFromStack(iBookEditorView);
00135             delete iBookEditorView;
00136             iBookEditorView = NULL;
00137             break;
00138 
00139         case ENone:
00140         default:
00141             break;
00142         }
00143     // Create new view (window owning control)
00144     switch(aNewView)
00145         {
00146         case EMainView:
00147             iAppView = CDBMSAppView::NewL(ClientRect());
00148             AddToStackL(iAppView);
00149             break;
00150 
00151         case EListView:
00152         case EColumnsView:
00153             iListboxView = CDBMSListboxView::NewL(ClientRect());
00154             AddToStackL(iListboxView);
00155             break;
00156 
00157         case EEditorView:
00158             iBookEditorView = CDBMSEditorView::NewL(ClientRect());
00159             AddToStackL(iBookEditorView);
00160             break;
00161 
00162         case ENone:
00163         default:
00164             break;
00165         }
00166     iCurrentView = aNewView;
00167     }
00168 
00169 
00170 // ---------------------------------------------------------------------------
00171 // CDBMSAppUi::DynInitMenuPaneL(...)
00172 //
00173 // Initialize menu before it is shown. This overrides default implementation
00174 // in base class.
00175 // ---------------------------------------------------------------------------
00176 //
00177 void CDBMSAppUi::DynInitMenuPaneL(TInt aResourceId,
00178     CEikMenuPane* aMenuPane)
00179     {
00180     if (aResourceId != R_MAIN_MENU)
00181         {
00182         return;
00183         }
00184 
00185     // First hide all menu items
00186     aMenuPane->SetItemDimmed(EOpenCmd, ETrue);
00187     aMenuPane->SetItemDimmed(ECreateCmd, ETrue);
00188     aMenuPane->SetItemDimmed(ERemoveDbCmd, ETrue);
00189     aMenuPane->SetItemDimmed(EAddBookCmd, ETrue);
00190     aMenuPane->SetItemDimmed(EBackCmd, ETrue);
00191     aMenuPane->SetItemDimmed(EAddBookAPICmd, ETrue);
00192     aMenuPane->SetItemDimmed(EAddBookSQLCmd, ETrue);
00193     aMenuPane->SetItemDimmed(ERemoveBookCmd, ETrue);
00194     aMenuPane->SetItemDimmed(ERemoveAllBooksCmd, ETrue);
00195     aMenuPane->SetItemDimmed(EChangeTitleCmd, ETrue);
00196     aMenuPane->SetItemDimmed(EGetAllBooksCmd, ETrue);
00197     aMenuPane->SetItemDimmed(ESearchBooksCmd, ETrue);
00198     aMenuPane->SetItemDimmed(EQuickFindCmd, ETrue);
00199     aMenuPane->SetItemDimmed(EAddDateCmd, ETrue);
00200     aMenuPane->SetItemDimmed(ERemoveDateCmd, ETrue);
00201     aMenuPane->SetItemDimmed(EColumnNamesCmd, ETrue);
00202     aMenuPane->SetItemDimmed(ECloseCmd, ETrue);
00203 
00204     // Show appropriate menu items depending on the current view
00205     switch(iCurrentView)
00206         {
00207         case EMainView:
00208             {
00209             // Db is not open. Allow creating, opening or removing the database
00210             if(BaflUtils::FileExists(CCoeEnv::Static()->FsSession(),
00211                 iDatabaseFile))
00212                 {
00213                 aMenuPane->SetItemDimmed(EOpenCmd, EFalse);
00214                 aMenuPane->SetItemDimmed(ERemoveDbCmd, EFalse);
00215                 }
00216             aMenuPane->SetItemDimmed(ECreateCmd, EFalse);
00217             break;
00218             }
00219 
00220         case EListView:
00221             {
00222             // DB is open, allow / show db operations
00223             if(iBookDb && iBookDb->IsOpen())
00224                 {
00225                 aMenuPane->SetItemDimmed(EAddBookCmd, EFalse);
00226                 aMenuPane->SetItemDimmed(ERemoveBookCmd, EFalse);
00227                 aMenuPane->SetItemDimmed(ERemoveAllBooksCmd, EFalse);
00228                 aMenuPane->SetItemDimmed(EChangeTitleCmd, EFalse);
00229                 aMenuPane->SetItemDimmed(EGetAllBooksCmd, EFalse);
00230                 aMenuPane->SetItemDimmed(ESearchBooksCmd, EFalse);
00231                 aMenuPane->SetItemDimmed(EQuickFindCmd, EFalse);
00232                 aMenuPane->SetItemDimmed(EColumnNamesCmd, EFalse);
00233                 aMenuPane->SetItemDimmed(ECloseCmd, EFalse);
00234                 }
00235             break;
00236             }
00237 
00238         case EColumnsView:
00239             {
00240             if(iBookDb && iBookDb->IsOpen())
00241                 {
00242                 // Get existence status of date column
00243                 TBool hasDateColumn(EFalse);
00244                 User::LeaveIfError(iBookDb->HasDateColumn(hasDateColumn));
00245 
00246                 aMenuPane->SetItemDimmed(EBackCmd, EFalse);
00247                 if(!hasDateColumn)
00248                     aMenuPane->SetItemDimmed(EAddDateCmd, EFalse);
00249                 else
00250                     aMenuPane->SetItemDimmed(ERemoveDateCmd, EFalse);
00251                 aMenuPane->SetItemDimmed(ECloseCmd, EFalse);
00252                 }
00253             break;
00254             }
00255 
00256         case EEditorView:
00257             {
00258             if(iBookDb && iBookDb->IsOpen())
00259                 {
00260                 aMenuPane->SetItemDimmed(EBackCmd, EFalse);
00261                 aMenuPane->SetItemDimmed(EAddBookAPICmd, EFalse);
00262                 aMenuPane->SetItemDimmed(EAddBookSQLCmd, EFalse);
00263                 aMenuPane->SetItemDimmed(ECloseCmd, EFalse);
00264                 }
00265             break;
00266             }
00267 
00268         case ENone:
00269         default:
00270             break;
00271         }
00272     }
00273 
00274 // ---------------------------------------------------------------------------
00275 // CDBMSAppUi::HandleCommandL(...)
00276 //
00277 // Handle menu commands.
00278 // ---------------------------------------------------------------------------
00279 //
00280 void CDBMSAppUi::HandleCommandL(TInt aCommand)
00281     {
00282 
00283     switch(aCommand)
00284         {
00285 
00286     case EOpenCmd:            // Open existing database
00287         OpenDatabaseL();
00288         break;
00289 
00290     case ECreateCmd:          // Create (replace) and open a database
00291         CreateDatabaseL();
00292         break;
00293 
00294     case ERemoveDbCmd:        // Drop database. Remove the database file
00295         RemoveDatabaseL();
00296         break;
00297 
00298     case EBackCmd:            // Move back from editor or columns view to
00299         ShowAllBooksL();      // list view
00300         break;
00301 
00302     case EAddBookCmd:         // Show a Book editor for adding a Book
00303         ShowBookEditorViewL();
00304         break;
00305 
00306     case EAddBookAPICmd:      // Add a Book using Book API
00307         AddBookL(EFalse);
00308         break;
00309 
00310     case EAddBookSQLCmd:      // Add a Book using SQL
00311         AddBookL(ETrue);
00312         break;
00313 
00314     case ERemoveBookCmd:      // Remove a named Book from database
00315         RemoveBookL();
00316         break;
00317 
00318     case ERemoveAllBooksCmd:  // Remove all Books from database
00319         RemoveAllBooksL();
00320         break;
00321 
00322     case EChangeTitleCmd:     // Update a Book title
00323         UpdateBookTitleL();
00324         break;
00325 
00326     case EGetAllBooksCmd:     // Read all Books from database
00327         ShowAllBooksL();
00328         break;
00329 
00330     case ESearchBooksCmd:     // Search Books with given search pattern
00331         SearchBooksL();
00332         break;
00333 
00334     case EQuickFindCmd:       // Find a Book using index
00335         IndexFindL();
00336         break;
00337 
00338     case EAddDateCmd:         // Add a date column to Books table
00339         AddDateColumnL();
00340         break;
00341 
00342     case ERemoveDateCmd:      // Remove the date column from Books table
00343         RemoveDateColumnL();
00344         break;
00345 
00346     case EColumnNamesCmd:     // Show column names of database
00347         ShowColumnsL();
00348         break;
00349 
00350     case ECloseCmd:           // Close database
00351         CloseDatabaseL();
00352         break;
00353 
00354     case EAknSoftkeyExit:     // From CBA
00355     case EEikCmdExit:         // From operating system / framework
00356         Exit();
00357         break;
00358 
00359     default:
00360         break;
00361         }
00362     }
00363 
00364 // ---------------------------------------------------------------------------
00365 // CDBMSAppUi::OpenDatabaseL()
00366 //
00367 // Create instance of iDBMSDb and open existing database.
00368 // ---------------------------------------------------------------------------
00369 void CDBMSAppUi::OpenDatabaseL()
00370     {
00371     iBookDb = CBookDb::NewL();
00372     iBookDb->OpenDb(iDatabaseFile);
00373     ShowAllBooksL(); // Change to list view
00374     }
00375 
00376 // ---------------------------------------------------------------------------
00377 // CDBMSAppUi::CreateDatabaseL()
00378 //
00379 // Create instance of iDBMSDb and create a new database.
00380 // ---------------------------------------------------------------------------
00381 //
00382 void CDBMSAppUi::CreateDatabaseL()
00383     {
00384     _LIT(KMessage,"Database created.");
00385     iBookDb = CBookDb::NewL();
00386     iBookDb->CreateDb(iDatabaseFile); // replaces, if exists
00387     ShowAllBooksL(); // Change to list view
00388     ShowNoteL(KMessage);
00389     }
00390 
00391 
00392 // ---------------------------------------------------------------------------
00393 // CDBMSAppUi::RemoveDatabaseL()
00394 //
00395 // Remove database file from the system.
00396 // ---------------------------------------------------------------------------
00397 //
00398 void CDBMSAppUi::RemoveDatabaseL()
00399     {
00400     _LIT(KMessage,"Database removed.");
00401     iBookDb = CBookDb::NewL();
00402     iBookDb->RemoveDb(iDatabaseFile);
00403     delete iBookDb;
00404     iBookDb = NULL;
00405     ShowNoteL(KMessage);
00406     }
00407 
00408 
00409 // ---------------------------------------------------------------------------
00410 // CDBMSAppUi::CloseDatabaseL()
00411 //
00412 // Close an open database. Database opened with OpenDatabaseL or
00413 // CreateDatabaseL must be closed, when not used any more.
00414 // ---------------------------------------------------------------------------
00415 //
00416 void CDBMSAppUi::CloseDatabaseL()
00417     {
00418     if(iBookDb && iBookDb->IsOpen())
00419         {
00420         iBookDb->Close();
00421         delete iBookDb;
00422         iBookDb = NULL;
00423         }
00424     ChangeViewL(EMainView);
00425     }
00426 
00427 
00428 // ---------------------------------------------------------------------------
00429 // CDBMSAppUi::ShowDBMSEditorView()
00430 //
00431 // Activate DBMS editor view
00432 // ---------------------------------------------------------------------------
00433 //
00434 void CDBMSAppUi::ShowBookEditorViewL()
00435     {
00436     ChangeViewL(EEditorView);
00437     }
00438 
00439 
00440 // ---------------------------------------------------------------------------
00441 // CDBMSAppUi::AddDBMSL()
00442 //
00443 // Add a Book to database. Query details from DBMS editor view.
00444 //
00445 // There are two variants for insertion. See DBEngine.h fordetails.
00446 // ---------------------------------------------------------------------------
00447 //
00448 void CDBMSAppUi::AddBookL(TBool aUseSql)
00449     {
00450 
00451     _LIT(KErrorMsg,"Failed. Make sure the fields are not empty.");
00452     TInt err(KErrNone);
00453 
00454     // Lengths are from DBEngine.h. Author uses default length (50)
00455     TBuf<50> author;
00456     TBuf<KTitleMaxLength> title;
00457     TBuf<KDescriptionMaxLength> description;
00458     
00459 
00460     iBookEditorView->GetAuthorL(author);
00461     iBookEditorView->GetTitleL(title);
00462     iBookEditorView->GetDescriptionL(description);
00463 
00464     if(aUseSql)
00465         err = iBookDb->AddBookWithSql(author,
00466                                             title,
00467                                             description);
00468     else
00469         err = iBookDb->AddBookWithCppApiL(author,
00470                                                title,
00471                                                description);
00472 
00473     if(err)
00474         ShowNoteL(KErrorMsg);
00475     else
00476         ShowAllBooksL(); // Change back to listbox view
00477         
00478     }
00479 
00480 
00481 // ---------------------------------------------------------------------------
00482 // CDBMSAppUi::RemoveDBMSL()
00483 //
00484 // Remove selected Book from the database.
00485 //
00486 // Implementation removes named Book from the database. If there are multiple
00487 // matches for the Book title, the are all removed.
00488 // ---------------------------------------------------------------------------
00489 //
00490 void CDBMSAppUi::RemoveBookL()
00491     {
00492 
00493     TBuf<KBookItemMaxLength> selectedBookTitle;
00494     if(iListboxView->GetSelectedItem(selectedBookTitle) != KErrNone)
00495         {
00496         _LIT(KErrorMsg,"Failed. Book not selected.");
00497         ShowNoteL(KErrorMsg);
00498         return;
00499         }
00500 
00501     TInt resultCount;
00502     // Wildcards are also allowed, like 'Title*', or '?itle"
00503     iBookDb->RemoveBooks(selectedBookTitle, resultCount);
00504     ShowAllBooksL();
00505     }
00506 
00507 
00508 // ---------------------------------------------------------------------------
00509 // CDBMSAppUi::RemoveAllDBMSsL()
00510 //
00511 // Remove all Books from database.
00512 // ---------------------------------------------------------------------------
00513 //
00514 void CDBMSAppUi::RemoveAllBooksL()
00515     {
00516     _LIT(KInfoText,"All Books removed.");
00517     TInt resultCount;
00518     iBookDb->RemoveAllBooks(resultCount);
00519     ShowNoteL(KInfoText);
00520     ShowAllBooksL();
00521     }
00522 
00523 
00524 // ---------------------------------------------------------------------------
00525 // CDBMSAppUi::UpdateDBMSTitleL()
00526 //
00527 // Change the title of a selected Book.
00528 // ---------------------------------------------------------------------------
00529 //
00530 void CDBMSAppUi::UpdateBookTitleL()
00531     {
00532     _LIT(KQuery,"New title(s) for: ");
00533     TBuf<KBookItemMaxLength> selectedBookTitle;
00534     if(iListboxView->GetSelectedItem(selectedBookTitle) != KErrNone)
00535         {
00536         _LIT(KErrorMsg,"Failed. Book not selected.");
00537         ShowNoteL(KErrorMsg);
00538         return;
00539         }
00540     TBuf<KBookItemMaxLength+32> prompt;
00541     TBuf<KBookItemMaxLength> newTitle;
00542 
00543     prompt.Append(KQuery);
00544     prompt.Append(selectedBookTitle);
00545 
00546     if(QueryTextL(prompt, newTitle))
00547         {
00548         newTitle.Trim(); // Remove specific characters from the beginning
00549                          // and the end of the string
00550         iBookDb->UpdateBookTitle(selectedBookTitle, newTitle);
00551         ShowAllBooksL();
00552         }
00553     }
00554 
00555 
00556 // ---------------------------------------------------------------------------
00557 // CDBMSAppUi::ShowAllDBMSsL()
00558 //
00559 // Get list of all Books in the database. Show the titles in the listbox
00560 // ---------------------------------------------------------------------------
00561 //
00562 void CDBMSAppUi::ShowAllBooksL()
00563     {
00564     _LIT(KAllBooksTitle,"Books in DBMS:");
00565 
00566     // Get array of full Book infos from the database. Construct array of
00567     // titles and show them in the listbox view.
00568 
00569     CDesCArrayFlat* Books = iBookDb->GetAllBooksL();
00570     CleanupStack::PushL(Books);
00571     CDesCArrayFlat* titles = TitlesArrayL(Books);
00572     CleanupStack::PushL(titles);
00573 
00574     ChangeViewL(EListView); // construct the listbox view
00575     iListboxView->SetCaptionL(KAllBooksTitle);
00576     CleanupStack::Pop(titles);
00577     iListboxView->SetListItemsL(titles); // Takes ownership
00578     CleanupStack::PopAndDestroy(Books);
00579 
00580     }
00581 
00582 
00583 // ---------------------------------------------------------------------------
00584 // CDBMSAppUi::SearchBooksL()
00585 //
00586 // Query Book search string from the user and perform Book search. Show the
00587 // results in the list.
00588 //
00589 // Implementation finds Books according to a KBooksTitleCol column name
00590 // and the queried search pattern.
00591 // ---------------------------------------------------------------------------
00592 //
00593 void CDBMSAppUi::SearchBooksL()
00594     {
00595     _LIT(KSearchResult, "Search result:");
00596     _LIT(KBookSearch, "Book search");
00597     _LIT(KWildCard, "*");
00598 
00599     TBuf<KTitleMaxLength> titlePattern;
00600     TBuf<32> prompt(KBookSearch);
00601 
00602     QueryTextL(prompt, titlePattern);
00603     titlePattern.Append(KWildCard);
00604 
00605     ChangeViewL(EListView);
00606     iListboxView->SetCaptionL(KSearchResult);
00607 
00608     // Get array of matching DBMSs. Construct array of titles from the
00609     // DBMSs array and show it in the listbox view.
00610 
00611     CDesCArrayFlat* Books =
00612         iBookDb->GetBooksByKeyL(KBooksTitleCol, titlePattern);
00613     CleanupStack::PushL(Books);
00614 
00615     CDesCArrayFlat* titles = TitlesArrayL(Books);
00616     iListboxView->SetListItemsL(titles); // Takes ownership
00617 
00618     CleanupStack::PopAndDestroy(Books);
00619     }
00620 
00621 
00622 // ---------------------------------------------------------------------------
00623 // CDBMSAppUi::IndexFindL()
00624 //
00625 // Find a Book using index. Show full info for the Book.
00626 // ---------------------------------------------------------------------------
00627 //
00628 void CDBMSAppUi::IndexFindL()
00629     {
00630     _LIT(KDetailsCaption,"Book details:");
00631 
00632     // Query the title of the selected Book in the listbox
00633     TBuf<KBookItemMaxLength> selectedBook;
00634     if(iListboxView->GetSelectedItem(selectedBook) != KErrNone)
00635     {
00636         _LIT(KErrorMsg,"Failed. Book not selected.");
00637         ShowNoteL(KErrorMsg);
00638         return;
00639     }
00640 
00641     // Query Book details from the database using Book title
00642     TBuf<KBookItemMaxLength> result;
00643     TInt err = iBookDb->GetABookFast(selectedBook, result);
00644     if(err==KErrNotFound)
00645         {
00646         _LIT(KNotFoundMsg,"Book not found.");
00647         ShowNoteL(KNotFoundMsg);
00648         return;
00649         }
00650     iEikonEnv->InfoWinL(KDetailsCaption, result);
00651     }
00652 
00653 
00654 // ---------------------------------------------------------------------------
00655 // CDBMSAppUi::AddDateColumn()
00656 //
00657 // Adds a date column to the Books table - if the column does not exist already
00658 // ---------------------------------------------------------------------------
00659 //
00660 void CDBMSAppUi::AddDateColumnL()
00661     {
00662         iBookDb->AddDateColumn();
00663         ShowColumnsL();
00664     }
00665 
00666 
00667 // ---------------------------------------------------------------------------
00668 // CDBMSAppUi::RemoveDateColumnL()
00669 //
00670 // Removes the date column from Books table - if the column exists
00671 // ---------------------------------------------------------------------------
00672 //
00673 void CDBMSAppUi::RemoveDateColumnL()
00674     {
00675         iBookDb->RemoveDateColumn();
00676         ShowColumnsL();
00677     }
00678 
00679 
00680 // ---------------------------------------------------------------------------
00681 // CDBMSAppUi::ShowColumns()
00682 //
00683 // Show the columns of the Book (Books table)
00684 // ---------------------------------------------------------------------------
00685 //
00686 void CDBMSAppUi::ShowColumnsL()
00687     {
00688     _LIT(KColumnsCaption,"Columns in Book:");
00689     ChangeViewL(EColumnsView); // construct the listbox view
00690     iListboxView->SetCaptionL(KColumnsCaption);
00691     CDesCArrayFlat* tmp = iBookDb->ColumnNamesAndSizesL();
00692     iListboxView->SetListItemsL(tmp); // takes ownership
00693     }
00694 
00695 
00696 // ---------------------------------------------------------------------------
00697 // CDBMSAppUi::ApplicationDriveAndPathL()
00698 //
00699 // Get the application path and drive. It must be done differently in the
00700 // development environment and in the device.
00701 // ---------------------------------------------------------------------------
00702 //
00703 TFileName CDBMSAppUi::ApplicationDriveAndPathL() const
00704     {
00705     TFileName appfullname(Application()->AppFullName());
00706     TParse parse;
00707 
00708 #ifdef __WINS__   // See macro definition in DBMSDb.mmp
00709 
00710     // On development environment the AppFullName points to z drive.
00711     // Replace it to point to C drive, which is writable by our application.
00712 
00713     parse.Set(KCDrive, &appfullname, NULL);
00714 
00715 #else // In device use the application fullname directly.
00716 
00717     parse.Set(appfullname, NULL, NULL);
00718 
00719 #endif
00720 
00721     TFileName fn = parse.DriveAndPath();
00722     // Make sure the path exists (create if not). This is needed in EMULATOR.
00723     BaflUtils::EnsurePathExistsL(CCoeEnv::Static()->FsSession(), fn);
00724     return fn;
00725     }
00726 
00727 // ---------------------------------------------------------------------------
00728 // CDBMSAppUi::DatabaseDriveAndPathL()
00729 // ---------------------------------------------------------------------------
00730 //
00731 TFileName CDBMSAppUi::DatabaseDriveAndPathL() const
00732 {       
00733         RFs fsSession;
00734         User::LeaveIfError(fsSession.Connect());
00735         CleanupClosePushL(fsSession);
00736         
00737     TFileName appfullname, fn;
00738     appfullname = Application()->AppFullName();
00739         fsSession.PrivatePath(fn);
00740 
00741 #ifdef __WINS__   // See macro definition in DBMS.mmp
00742         fn.Insert(0,KCDrive);
00743 
00744 #else // In device use the application fullname directly.
00745     TParse parse;
00746     parse.Set(appfullname, NULL, NULL);
00747     fn.Insert(0,parse.Drive());   
00748 #endif
00749 
00750     BaflUtils::EnsurePathExistsL(fsSession, fn);
00751         CleanupStack::PopAndDestroy(&fsSession);
00752         
00753     return fn;
00754 }
00755 
00756 // ---------------------------------------------------------------------------
00757 // CDBMSAppUi::ShowNoteL()
00758 //
00759 // Show a note. Note that successive frequent calls to this method results in
00760 // showing the latest message only.
00761 // ---------------------------------------------------------------------------
00762 //
00763 void CDBMSAppUi::ShowNoteL(const TDesC& aMessage) const
00764     {
00765 
00766     CAknInformationNote* note = new(ELeave)CAknInformationNote;
00767     note->ExecuteLD(aMessage); // Deletes itself, when returns
00768     }
00769 
00770 
00771 // ---------------------------------------------------------------------------
00772 // CDBMSAppUi::TitlesArrayL()
00773 //
00774 // Build an array of Book titles from an array having Books with full info.
00775 // ---------------------------------------------------------------------------
00776 //
00777 CDesCArrayFlat* CDBMSAppUi::TitlesArrayL(
00778     const CDesCArrayFlat* aFullDBMSInfoArray) const
00779     {
00780     // Assume the items within aFullDBMSInfoArray are in the format:
00781     // <Author>|<Title>|<Description>
00782 
00783     CDesCArrayFlat* resultArray =
00784         new (ELeave)CDesC16ArrayFlat(KArrayGranularity);
00785     CleanupStack::PushL(resultArray);
00786 
00787     TPtrC16 sourceRow;
00788     TInt startPos = 0;
00789     TInt endPos = 0;
00790 
00791     // Iterate through the DBMSs.
00792     // From each DBMS row, parse the <Title> and append it to result array.
00793     for(TInt i=0; i<aFullDBMSInfoArray->MdcaCount(); i++)
00794         {
00795         sourceRow.Set(aFullDBMSInfoArray->MdcaPoint(i));
00796         startPos = sourceRow.Locate('|') + 1; // exclude '|' from result
00797         endPos = sourceRow.LocateReverse('|');
00798         resultArray->AppendL(sourceRow.Mid(startPos, endPos-startPos));
00799         }
00800     CleanupStack::Pop(resultArray);
00801     return resultArray;
00802     }
00803 
00804 // ---------------------------------------------------------------------------
00805 // CDBMSAppUi::QueryTextL()
00806 //
00807 // Show simple text query dialos for the user
00808 // ---------------------------------------------------------------------------
00809 //
00810 TBool CDBMSAppUi::QueryTextL(TDesC& aPrompt,
00811     TDes& aResultText) const
00812     {
00813    // Note: aPrompt cannot be const TDesC&, because CAknTextQueryDialog
00814    //       does not accept const TDesC& as a second parameter.
00815 
00816     CAknTextQueryDialog* dlg = new(ELeave)
00817         CAknTextQueryDialog( aResultText, // result is placed here
00818                              aPrompt,
00819                              CAknTextQueryDialog::ENoTone );
00820 
00821     dlg->SetMaxLength(aResultText.MaxLength());
00822     return dlg->ExecuteLD(R_SIMPLE_TEXT_QUERY);
00823     }
00824 
00825 // ---------------------------------------------------------
00826 // CDBMSAppView::HandleStatusPaneSizeChange()
00827 // Called by framework when resource is changed.
00828 // ---------------------------------------------------------
00829 //
00830 void CDBMSAppUi::HandleStatusPaneSizeChange()
00831         {
00832         CAknAppUi::HandleStatusPaneSizeChange(); //call to upper class
00833 
00834     if(iAppView)
00835         iAppView->SetRect( ClientRect() );
00836     if(iListboxView)
00837         iListboxView->SetRect( ClientRect() );
00838     if(iBookEditorView)
00839         iBookEditorView->SetRect( ClientRect() );
00840         }
00841         
00842 //EOF

Generated by  doxygen 1.6.2