filebrowser/ui/src/fbfolderselectiondialog.cpp
changeset 51 b048e15729d6
equal deleted inserted replaced
44:5db69f4c3d06 51:b048e15729d6
       
     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 
       
    18 #include "fbfolderselectiondialog.h"
       
    19 #include "fbfolderselectorwrapper.h"
       
    20 
       
    21 #include <HbListWidget>
       
    22 #include <HbAction>
       
    23 #include <HbListWidgetItem>
       
    24 #include <HbLabel>
       
    25 #include <HbPushButton>
       
    26 
       
    27 #include <QGraphicsLinearLayout>
       
    28 #include <QFileInfo>
       
    29 #include <QFileIconProvider>
       
    30 
       
    31 FbFolderSelectionDialog::FbFolderSelectionDialog(QGraphicsItem *parent) :
       
    32         HbDialog(parent),
       
    33         mTitle(0),
       
    34         mFolderList(0),
       
    35         mFolderSelectorWrapper(0),
       
    36         mFileIconProvider(0)
       
    37 {
       
    38     init();
       
    39 }
       
    40 
       
    41 FbFolderSelectionDialog::~FbFolderSelectionDialog()
       
    42 {
       
    43     if (mFileIconProvider)
       
    44         delete mFileIconProvider;
       
    45 }
       
    46 
       
    47 QString FbFolderSelectionDialog::selectedFolder()
       
    48 {
       
    49     return mFolderSelectorWrapper->currentPath();
       
    50 }
       
    51 
       
    52 void FbFolderSelectionDialog::init()
       
    53 {
       
    54     setAttribute(Qt::WA_DeleteOnClose);
       
    55 
       
    56     mFileIconProvider = new QFileIconProvider();
       
    57 
       
    58     createHeading();
       
    59     createList();
       
    60     createToolBar();
       
    61 }
       
    62 
       
    63 void FbFolderSelectionDialog::createHeading()
       
    64 {
       
    65     HbWidget *headingWidget = new HbWidget(this);
       
    66     QGraphicsLinearLayout *headingLayout = new QGraphicsLinearLayout(Qt::Horizontal, headingWidget);
       
    67     headingWidget->setLayout(headingLayout);
       
    68 
       
    69     mTitle = new HbLabel(this);
       
    70     mTitle->setElideMode(Qt::ElideRight);
       
    71 
       
    72     HbPushButton *upButton = new HbPushButton(this);
       
    73     upButton->setIcon(HbIcon(QString(":/qtg_indi_status_back.svg")));
       
    74     connect(upButton, SIGNAL(pressed()),
       
    75             this, SLOT(moveUpPressed()));
       
    76 
       
    77     headingLayout->addItem(mTitle);
       
    78     headingLayout->addItem(upButton);
       
    79     headingLayout->setAlignment(upButton, Qt::AlignRight);
       
    80 
       
    81     setHeadingWidget(headingWidget);
       
    82 }
       
    83 
       
    84 void FbFolderSelectionDialog::createList()
       
    85 {
       
    86     mFolderList = new HbListWidget(this);
       
    87     mFolderSelectorWrapper = new FbFolderSelectorWrapper();
       
    88     mFolderSelectorWrapper->init();
       
    89 
       
    90     refreshView();
       
    91 
       
    92     setContentWidget(mFolderList);
       
    93     connect(mFolderList, SIGNAL(activated(HbListWidgetItem *)),
       
    94             this, SLOT(activated(HbListWidgetItem *)));
       
    95 
       
    96     connect(mFolderSelectorWrapper, SIGNAL(FolderSelectionChanged()),
       
    97             this, SLOT(refreshView()));
       
    98 }
       
    99 
       
   100 void FbFolderSelectionDialog::createToolBar()
       
   101 {
       
   102     HbAction *rejectAction = new HbAction(QString("Cancel"), this);
       
   103     addAction(rejectAction);
       
   104 }
       
   105 
       
   106 void FbFolderSelectionDialog::refreshView()
       
   107 {
       
   108     mFolderList->clear();
       
   109     QIcon icon;
       
   110     if (mFolderSelectorWrapper->isDriveListViewActive())
       
   111     {
       
   112         const QString KSimpleDriveEntry("%d\t%c: <%S>\t\t");
       
   113         //TODO icon = mFileIconProvider->icon(QFileIconProvider::Drive);
       
   114         icon = mFileIconProvider->icon(QFileIconProvider::File);
       
   115 
       
   116         for (TInt i=0; i<mFolderSelectorWrapper->itemCount(); i++) {
       
   117             FbDriveEntry driveEntry = mFolderSelectorWrapper->getDriveEntry(i);
       
   118 
       
   119             const QString SimpleDriveEntry("%1: <%2>");
       
   120             QString diskName = SimpleDriveEntry.arg(driveEntry.driveLetter()).arg(driveEntry.mediaTypeString());
       
   121 
       
   122             mFolderList->addItem(icon, diskName);
       
   123         }
       
   124     } else {
       
   125         const QString SimpleFileEntry("%1");
       
   126         icon = mFileIconProvider->icon(QFileIconProvider::Folder);
       
   127 
       
   128         // append current folder item
       
   129         QString currentAbsolutePath = mFolderSelectorWrapper->currentPath().left(mFolderSelectorWrapper->currentPath().length()-1);
       
   130         QFileInfo fileInfo(currentAbsolutePath);
       
   131         QString currentFolderName = fileInfo.fileName();
       
   132         if (currentFolderName.isEmpty()) {
       
   133             currentFolderName = QString("[root level]");
       
   134         }
       
   135 
       
   136         QString currentDirTextEntry = SimpleFileEntry.arg(currentFolderName); ///*<< fileEntry.IconId()*/
       
   137         mFolderList->addItem(icon, currentDirTextEntry);
       
   138 
       
   139         for (TInt i=0; i<mFolderSelectorWrapper->itemCount(); i++) {
       
   140             FbFileEntry fileEntry = mFolderSelectorWrapper->getFileEntry(i);
       
   141 
       
   142             QString fileName = SimpleFileEntry.arg(fileEntry.name()); ///*<< fileEntry.IconId()*/
       
   143 
       
   144             mFolderList->addItem(icon, fileName);
       
   145         }
       
   146     }
       
   147 }
       
   148 
       
   149 void FbFolderSelectionDialog::activated(HbListWidgetItem * item)
       
   150 {
       
   151     int row = mFolderList->row(item);
       
   152     if (mFolderSelectorWrapper->isDriveListViewActive()) {
       
   153         mFolderSelectorWrapper->moveDownToDirectory(row);
       
   154     } else if (row == 0) {
       
   155         if (this->actions().count() > 0) {
       
   156             accept();
       
   157         }
       
   158     } else if (row > 0) {
       
   159         mFolderSelectorWrapper->moveDownToDirectory(row);
       
   160     }
       
   161 }
       
   162 
       
   163 void FbFolderSelectionDialog::moveUpPressed()
       
   164 {
       
   165     mFolderSelectorWrapper->moveUpOneLevel();
       
   166 }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 
       
   170 FbCopyToFolderSelectionDialog::FbCopyToFolderSelectionDialog(QGraphicsItem *parent) :
       
   171         FbFolderSelectionDialog(parent)
       
   172 {
       
   173     if (headingWidget()) {
       
   174         mTitle->setPlainText(QString("Copy To"));
       
   175     }
       
   176 }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 
       
   180 FbMoveToFolderSelectionDialog::FbMoveToFolderSelectionDialog(QGraphicsItem *parent) :
       
   181         FbFolderSelectionDialog(parent)
       
   182 {
       
   183     if (headingWidget()) {
       
   184         mTitle->setPlainText(QString("Move To"));
       
   185     }
       
   186 }
       
   187 
       
   188 // End of file