filebrowser/ui/src/fbmainwindow.cpp
changeset 55 2d9cac8919d3
parent 53 819e59dfc032
child 56 392f7045e621
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 
       
    29 FbMainWindow::FbMainWindow(QWidget *parent)
       
    30     : HbMainWindow(parent),
       
    31     mEngineWrapper(0),
       
    32     mDriveView(0),
       
    33     mFileView(0),
       
    34     mSettingsView(0),
       
    35     mEditorView(0),
       
    36     mSearchView(0),
       
    37     mAttributesView(0),
       
    38     mPreviousView(0)
       
    39 {
       
    40 }
       
    41 
       
    42 FbMainWindow::~FbMainWindow ()
       
    43 {
       
    44     if (mEngineWrapper) {
       
    45         delete mEngineWrapper;
       
    46     }
       
    47 }
       
    48 
       
    49 void FbMainWindow::init()
       
    50 {
       
    51     // Create Engine Wrapper and initialize it
       
    52     mEngineWrapper = new EngineWrapper();
       
    53     int error = mEngineWrapper->init();
       
    54     Q_ASSERT_X(error == 1, "FileBrowser", "Engine initialization failed");
       
    55 
       
    56     // Create drive view
       
    57     mDriveView = new FbDriveView();
       
    58     connect(mDriveView, SIGNAL(aboutToShowSettingsView()), this, SLOT(openSettingsView()));
       
    59     connect(mDriveView, SIGNAL(aboutToShowFileView()), this, SLOT(openFileView()));
       
    60     mDriveView->init(mEngineWrapper);
       
    61     addView(mDriveView);
       
    62 
       
    63     // Create file view
       
    64     mFileView = new FbFileView();
       
    65     connect(mFileView, SIGNAL(aboutToShowSettingsView()), this, SLOT(openSettingsView()));
       
    66     connect(mFileView, SIGNAL(aboutToShowDriveView()), this, SLOT(openDriveView()));
       
    67     mFileView->init(mEngineWrapper);
       
    68     addView(mFileView);
       
    69 
       
    70     // Create settings view
       
    71     mSettingsView = new FbSettingsView(*mEngineWrapper);
       
    72     connect(mSettingsView, SIGNAL(finished(bool)), this, SLOT(openPreviousBrowserView()));
       
    73     addView(mSettingsView);
       
    74 
       
    75     // Create editor view
       
    76     mEditorView = new FbEditorView();
       
    77     connect(mFileView, SIGNAL(aboutToShowEditorView(const QString &, bool)), this, SLOT(openEditorView(const QString &, bool)));
       
    78     connect(mEditorView, SIGNAL(finished(bool)), this, SLOT(openFileView()));
       
    79     addView(mEditorView);
       
    80 
       
    81     // Create Search view
       
    82     mSearchView = new FbSearchView(*mEngineWrapper);
       
    83     connect(mDriveView, SIGNAL(aboutToShowSearchView(QString)), this, SLOT(openSearchView(QString)));
       
    84     connect(mFileView, SIGNAL(aboutToShowSearchView(QString)), this, SLOT(openSearchView(QString)));
       
    85     connect(mSearchView, SIGNAL(finished(bool)), this, SLOT(openFileBrowserView(bool)));
       
    86     addView(mSearchView);
       
    87 
       
    88     connect(mFileView, SIGNAL(aboutToShowAttributesView(const QString &, quint32 &, quint32 &, bool &)),
       
    89             this, SLOT(openAttributesView(const QString &, quint32 &, quint32 &, bool &)));
       
    90 
       
    91     // Show ApplicationView at startup
       
    92     setCurrentView(mDriveView);
       
    93     mPreviousView = mDriveView;
       
    94 
       
    95     // Show HbMainWindow
       
    96     show();
       
    97 }
       
    98 
       
    99 
       
   100 void FbMainWindow::openPreviousBrowserView()
       
   101 {
       
   102     mDriveView->refreshList();
       
   103     mFileView->refreshList();
       
   104     setCurrentView(mPreviousView);
       
   105 }
       
   106 
       
   107 void FbMainWindow::openFileBrowserView(bool accepted)
       
   108 {
       
   109     mDriveView->refreshList();
       
   110     mFileView->refreshList();
       
   111     if (accepted) {
       
   112         setCurrentView(mFileView);
       
   113     } else {
       
   114         setCurrentView(mPreviousView);
       
   115     }
       
   116 }
       
   117 
       
   118 void FbMainWindow::openDriveView()
       
   119 {
       
   120     mDriveView->refreshList();
       
   121     setCurrentView(mDriveView);
       
   122     mPreviousView = mDriveView;
       
   123 }
       
   124 
       
   125 void FbMainWindow::openFileView()
       
   126 {
       
   127     mDriveView->refreshList();
       
   128 //    mFileView->setCurrentpath(path);
       
   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     mSearchView->open(path);
       
   149     setCurrentView(mSearchView);
       
   150 }
       
   151 
       
   152 void FbMainWindow::openAttributesView(const QString &attributesViewTitle,
       
   153                                       quint32 &setAttributesMask,
       
   154                                       quint32 &clearAttributesMask,
       
   155                                       bool &recurse)
       
   156 {
       
   157     if (!mAttributesView) {
       
   158         // Create attributes view
       
   159         mAttributesView = new FbAttributesView(setAttributesMask, clearAttributesMask, recurse);
       
   160         connect(mAttributesView, SIGNAL(finished(bool)), this, SLOT(closeAttributesView(bool)));
       
   161         mAttributesView->setTitle(attributesViewTitle);
       
   162         addView(mAttributesView);
       
   163         setCurrentView(mAttributesView);
       
   164     }
       
   165 }
       
   166 
       
   167 void FbMainWindow::closeAttributesView(bool accepted)
       
   168 {
       
   169     if (accepted) {
       
   170         mEngineWrapper->setAttributes(mAttributesView->setAttributesMask(), mAttributesView->clearAttributesMask(), mAttributesView->recurse());
       
   171     }
       
   172     openFileView();
       
   173     removeView(mAttributesView);
       
   174     mAttributesView->deleteLater();
       
   175     mAttributesView = 0;
       
   176 }
       
   177 
       
   178 // End of file