examples/ForumNokia/DBMS/src/DBMSAppui.cpp

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

Generated by  doxygen 1.6.2