utilityapps/filebrowser/ui/src/fbmainwindow.cpp
changeset 55 2d9cac8919d3
equal deleted inserted replaced
53:819e59dfc032 55:2d9cac8919d3
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <HbApplication>
       
    18 #include <HbMainWindow>
       
    19 
       
    20 #include "fbmainwindow.h"
       
    21 #include "enginewrapper.h"
       
    22 #include "fbfileview.h"
       
    23 #include "fbdriveview.h"
       
    24 #include "fbsettingsview.h"
       
    25 #include "fbeditorview.h"
       
    26 #include "fbsearchview.h"
       
    27 #include "fbattributesview.h"
       
    28 #include "notifications.h"
       
    29 
       
    30 #include <QWidget>
       
    31 
       
    32 FbMainWindow::FbMainWindow(QWidget *parent)
       
    33     : HbMainWindow(parent),
       
    34     mEngineWrapper(0),
       
    35     mDriveView(0),
       
    36     mFileView(0),
       
    37     mSettingsView(0),
       
    38     mEditorView(0),
       
    39     mSearchView(0),
       
    40     mAttributesView(0),
       
    41     mPreviousView(0)
       
    42 {
       
    43 }
       
    44 
       
    45 FbMainWindow::~FbMainWindow ()
       
    46 {
       
    47     if (mEngineWrapper) {
       
    48         delete mEngineWrapper;
       
    49     }
       
    50 }
       
    51 
       
    52 void FbMainWindow::init()
       
    53 {
       
    54     // Create Engine Wrapper and initialize it
       
    55     mEngineWrapper = new EngineWrapper();
       
    56     int error = mEngineWrapper->init();
       
    57     Q_ASSERT_X(error == 1, "FileBrowser", "Engine initialization failed");
       
    58 
       
    59     // Create drive view
       
    60     mDriveView = new FbDriveView();
       
    61     connect(mDriveView, SIGNAL(aboutToShowSettingsView()), this, SLOT(openSettingsView()));
       
    62     connect(mDriveView, SIGNAL(aboutToShowFileView()), this, SLOT(openFileView()));
       
    63     mDriveView->init(mEngineWrapper);
       
    64     addView(mDriveView);
       
    65 
       
    66     // Create file view
       
    67     mFileView = new FbFileView();
       
    68     connect(mFileView, SIGNAL(aboutToShowSettingsView()), this, SLOT(openSettingsView()));
       
    69     connect(mFileView, SIGNAL(aboutToShowDriveView()), this, SLOT(openDriveView()));
       
    70     mFileView->init(mEngineWrapper);
       
    71     addView(mFileView);
       
    72 
       
    73     // Create settings view
       
    74     mSettingsView = new FbSettingsView(*mEngineWrapper);
       
    75     connect(mSettingsView, SIGNAL(finished(bool)), this, SLOT(openPreviousBrowserView()));
       
    76     addView(mSettingsView);
       
    77 
       
    78     // Create editor view
       
    79     mEditorView = new FbEditorView();
       
    80     connect(mFileView, SIGNAL(aboutToShowEditorView(const QString &, bool)), this, SLOT(openEditorView(const QString &, bool)));
       
    81     connect(mEditorView, SIGNAL(finished(bool)), this, SLOT(openFileView()));
       
    82     addView(mEditorView);
       
    83 
       
    84     // Create Search view
       
    85     connect(mDriveView, SIGNAL(aboutToShowSearchView(QString)), this, SLOT(openSearchView(QString)));
       
    86     connect(mFileView, SIGNAL(aboutToShowSearchView(QString)), this, SLOT(openSearchView(QString)));
       
    87 
       
    88     // Create Attributes view
       
    89     connect(mFileView, SIGNAL(aboutToShowAttributesView(const QString &, quint32 &, quint32 &, bool &)),
       
    90             this, SLOT(openAttributesView(const QString &, quint32 &, quint32 &, bool &)));
       
    91 
       
    92     // Show ApplicationView at startup
       
    93     setCurrentView(mDriveView);
       
    94     mPreviousView = mDriveView;
       
    95 
       
    96     // Show HbMainWindow
       
    97     show();
       
    98 }
       
    99 
       
   100 
       
   101 void FbMainWindow::openPreviousBrowserView()
       
   102 {
       
   103     mDriveView->refreshList();
       
   104     mFileView->refreshList();
       
   105     setCurrentView(mPreviousView);
       
   106 }
       
   107 
       
   108 void FbMainWindow::openFileBrowserView(bool accepted)
       
   109 {
       
   110     mDriveView->refreshList();
       
   111     mFileView->refreshList();
       
   112     if (accepted) {
       
   113         setCurrentView(mFileView);
       
   114     } else {
       
   115         setCurrentView(mPreviousView);
       
   116     }
       
   117 }
       
   118 
       
   119 void FbMainWindow::openDriveView()
       
   120 {
       
   121     mDriveView->refreshList();
       
   122     setCurrentView(mDriveView);
       
   123     mPreviousView = mDriveView;
       
   124 }
       
   125 
       
   126 void FbMainWindow::openFileView()
       
   127 {
       
   128     mDriveView->refreshList();
       
   129     mFileView->refreshList();
       
   130     setCurrentView(mFileView);
       
   131     mPreviousView = mFileView;
       
   132 }
       
   133 
       
   134 void FbMainWindow::openSettingsView()
       
   135 {
       
   136     mSettingsView->initDataForm();
       
   137     setCurrentView(mSettingsView);
       
   138 }
       
   139 
       
   140 void FbMainWindow::openEditorView(const QString &fileName, bool flagReadOnly)
       
   141 {
       
   142     mEditorView->open(fileName, flagReadOnly);
       
   143     setCurrentView(mEditorView);
       
   144 }
       
   145 
       
   146 void FbMainWindow::openSearchView(const QString &path)
       
   147 {
       
   148     if (!mSearchView) {
       
   149         mSearchView = new FbSearchView();
       
   150         connect(mSearchView, SIGNAL(finished(bool)), this, SLOT(closeSearchView(bool)));
       
   151         mSearchView->open(mEngineWrapper->getFileSearchAttributes(), path);
       
   152         addView(mSearchView);
       
   153         setCurrentView(mSearchView);
       
   154     }
       
   155 }
       
   156 
       
   157 void FbMainWindow::closeSearchView(bool accepted)
       
   158 {
       
   159     if (accepted) {
       
   160         mSearchView->startFileSearch(mEngineWrapper);
       
   161     }
       
   162 
       
   163     removeView(mSearchView);
       
   164     mSearchView->deleteLater();
       
   165     mSearchView = 0;
       
   166     openFileView();
       
   167 }
       
   168 
       
   169 void FbMainWindow::openAttributesView(const QString &attributesViewTitle,
       
   170                                       quint32 &setAttributesMask,
       
   171                                       quint32 &clearAttributesMask,
       
   172                                       bool &recurse)
       
   173 {
       
   174     if (!mAttributesView) {
       
   175         // Create attributes view
       
   176         mAttributesView = new FbAttributesView(setAttributesMask, clearAttributesMask, recurse);
       
   177         connect(mAttributesView, SIGNAL(finished(bool)), this, SLOT(closeAttributesView(bool)));
       
   178         mAttributesView->setTitle(attributesViewTitle);
       
   179         addView(mAttributesView);
       
   180         setCurrentView(mAttributesView);
       
   181     }
       
   182 }
       
   183 
       
   184 void FbMainWindow::closeAttributesView(bool accepted)
       
   185 {
       
   186     if (accepted) {
       
   187         mEngineWrapper->setAttributes(mAttributesView->setAttributesMask(), mAttributesView->clearAttributesMask(), mAttributesView->recurse());
       
   188     }
       
   189     openFileView();
       
   190     removeView(mAttributesView);
       
   191     mAttributesView->deleteLater();
       
   192     mAttributesView = 0;
       
   193 }
       
   194 
       
   195 // End of file