filemanager/src/filemanager/src/components/fmdlgutils.cpp
changeset 16 ada7962b4308
parent 14 1957042d8c7e
child 18 edd66bde63a4
child 25 b7bfdea70ca2
child 37 15bc28c9dd51
equal deleted inserted replaced
14:1957042d8c7e 16:ada7962b4308
    20 #include "fmcombinedquery.h"
    20 #include "fmcombinedquery.h"
    21 #include "fmtimequery.h"
    21 #include "fmtimequery.h"
    22 #include "fmsingletextquery.h"
    22 #include "fmsingletextquery.h"
    23 #include "fmmultitextquery.h"
    23 #include "fmmultitextquery.h"
    24 #include "fmutils.h"
    24 #include "fmutils.h"
       
    25 #include "fmviewmanager.h"
    25 
    26 
    26 #include <QString>
    27 #include <QString>
    27 #include <QStringList>
    28 #include <QStringList>
    28 #include <QMap>
    29 #include <QMap>
    29 
    30 
    36 }
    37 }
    37 
    38 
    38 FmDlgUtils::~FmDlgUtils( void )
    39 FmDlgUtils::~FmDlgUtils( void )
    39 {
    40 {
    40 }
    41 }
       
    42 HbAction *FmDlgUtils::executeDialog( HbDialog *dialog, const QString &associatedDrives )
       
    43 {
       
    44     for( int i = 0; i < associatedDrives.length(); i++ ) {
       
    45         QString drive( associatedDrives[i] + QString( ":/" ) );
       
    46         if( !FmUtils::isDriveAvailable( drive ) ) {
       
    47             FmLogger::log( "executeDialog return 0_ " + associatedDrives );
       
    48             return 0;
       
    49         }
       
    50     }
       
    51     
       
    52 	FmDlgCloseUnit dlgCloseUnit( dialog );
       
    53 	dlgCloseUnit.addAssociatedDrives( associatedDrives );
       
    54 
       
    55 	FmViewManager::viewManager()->addDlgCloseUnit( &dlgCloseUnit );
       
    56     HbAction* action = dialog->exec();
       
    57 	FmViewManager::viewManager()->removeDlgCloseUnit( &dlgCloseUnit );
       
    58 	return action;
       
    59 }
    41 
    60 
    42 bool FmDlgUtils::showSingleSettingQuery(
    61 bool FmDlgUtils::showSingleSettingQuery(
    43         const QString &title,
    62         const QString &title,
    44         const QStringList &textList,
    63         const QStringList &textList,
    45         int &selectedIndex )
    64         int &selectedIndex, const QString &associatedDrives )
    46 {
    65 {
    47    bool ret( false );
    66    bool ret( false );
    48 
    67 
    49     int i = 0;
    68     int i = 0;
    50     QMap< int, QString > items;   // Maps list item with corresponding text in viewer
    69     QMap< int, QString > items;   // Maps list item with corresponding text in viewer
    64     }
    83     }
    65 
    84 
    66     QString sk1 ( tr ( "ok" ) );
    85     QString sk1 ( tr ( "ok" ) );
    67     QString sk2 ( tr ("cancel" ) );
    86     QString sk2 ( tr ("cancel" ) );
    68 
    87 
    69     if(sk1.isEmpty() == false) {
    88     if( !sk1.isEmpty() ) {
    70         HbAction *primary = new HbAction( sk1 );
    89         HbAction *primary = new HbAction( sk1 );
    71         cQuery->setPrimaryAction( primary );
    90         cQuery->setPrimaryAction( primary );
    72     }
    91     }
    73 
    92 
    74     if( sk2.isEmpty() == false ) {
    93     if( !sk2.isEmpty() ) {
    75         HbAction *secondary = new HbAction( sk2 );
    94         HbAction *secondary = new HbAction( sk2 );
    76         cQuery->setSecondaryAction( secondary );
    95         cQuery->setSecondaryAction( secondary );
    77     }
    96     }
    78     HbAction* action = cQuery->exec();
    97 
    79     if( action == cQuery->secondaryAction() ){
    98     //HbAction* action = cQuery->exec();
       
    99 	HbAction* action = executeDialog( cQuery, associatedDrives );
       
   100     if( action == cQuery->primaryAction() ){
       
   101         ok = true;
       
   102     }
       
   103     else{
    80         ok = false;
   104         ok = false;
    81     }
       
    82     else{
       
    83         ok = true;
       
    84     }
   105     }
    85     if( ok ){
   106     if( ok ){
    86         //get selected key list.
   107         //get selected key list.
    87         QList<int> selectedKeyList = cQuery->selectedKeys();
   108         QList<int> selectedKeyList = cQuery->selectedKeys();
    88 
   109 
   108 
   129 
   109 bool FmDlgUtils::showMultiSettingQuery(
   130 bool FmDlgUtils::showMultiSettingQuery(
   110         const QString &title,
   131         const QString &title,
   111         const QStringList &textList,
   132         const QStringList &textList,
   112         quint32 &selection,
   133         quint32 &selection,
   113         int dominantIndex )
   134         int dominantIndex, const QString &associatedDrives )
   114 {
   135 {
   115     bool ret( false );
   136     bool ret( false );
   116 
   137 
   117     int i = 0;
   138     int i = 0;
   118     QMap<int, QString> items;   // Maps list item with corresponding text in viewer
   139     QMap<int, QString> items;   // Maps list item with corresponding text in viewer
   135             cQuery->setMarkedListItem( i );
   156             cQuery->setMarkedListItem( i );
   136         }
   157         }
   137     }
   158     }
   138 
   159 
   139 
   160 
   140     QString sk1 ( tr( "ok" ) );
   161     QString sk1 ( hbTrId( "ok" ) );
   141     QString sk2 ( tr( "cancel" ) );
   162     QString sk2 ( hbTrId( "cancel" ) );
   142 
   163 
   143     if(sk1.isEmpty() == false) {
   164     if( !sk1.isEmpty() ) {
   144         HbAction *primary = new HbAction( sk1 );
   165         HbAction *primary = new HbAction( sk1 );
   145         cQuery->setPrimaryAction( primary );
   166         cQuery->setPrimaryAction( primary );
   146     }
   167     }
   147 
   168 
   148     if( sk2.isEmpty() == false ) {
   169     if( !sk2.isEmpty() ) {
   149         HbAction *secondary = new HbAction( sk2 );
   170         HbAction *secondary = new HbAction( sk2 );
   150         cQuery->setSecondaryAction( secondary );
   171         cQuery->setSecondaryAction( secondary );
   151     }
   172     }
   152     HbAction* action = cQuery->exec();
   173 
   153     if( action == cQuery->secondaryAction() ){
   174     HbAction* action = executeDialog( cQuery, associatedDrives );
       
   175     if( action == cQuery->primaryAction() ){
       
   176         ok = true;
       
   177     }
       
   178     else{
   154         ok = false;
   179         ok = false;
   155     }
       
   156     else{
       
   157         ok = true;
       
   158     }
   180     }
   159     if( ok )
   181     if( ok )
   160     {
   182     {
   161         //get selected key list.
   183         //get selected key list.
   162         QList<int> selectedKeyList = cQuery->selectedKeys();
   184         QList<int> selectedKeyList = cQuery->selectedKeys();
   179     delete cQuery;
   201     delete cQuery;
   180     return ret;
   202     return ret;
   181 }
   203 }
   182 
   204 
   183 bool FmDlgUtils::showTimeSettingQuery(
   205 bool FmDlgUtils::showTimeSettingQuery(
   184         const QString &title, QTime &time )
   206         const QString &title, QTime &time, const QString &associatedDrives )
   185 {
   207 {
   186     bool ret( false );
   208     bool ret( false );
   187     bool ok ( false );                // SK return (out parameter)
   209     bool ok ( false );                // SK return (out parameter)
   188 
   210 
   189     FmTimeQuery *cQuery=new FmTimeQuery;
   211     FmTimeQuery *cQuery=new FmTimeQuery;
   190     cQuery->setHeadingWidget( new HbLabel( title ) );
   212     cQuery->setHeadingWidget( new HbLabel( title ) );
   191     cQuery->setTime( time );
   213     cQuery->setTime( time );
   192 
   214 
   193     QString sk1 ( tr( "ok" ) );
   215     QString sk1 ( hbTrId( "ok" ) );
   194     QString sk2 ( tr( "cancel" ) );
   216     QString sk2 ( hbTrId( "cancel" ) );
   195 
   217 
   196     if(sk1.isEmpty() == false) {
   218     if( !sk1.isEmpty() ) {
   197         HbAction *primary = new HbAction( sk1 );
   219         HbAction *primary = new HbAction( sk1 );
   198         cQuery->setPrimaryAction( primary );
   220         cQuery->setPrimaryAction( primary );
   199     }
   221     }
   200 
   222 
   201     if( sk2.isEmpty() == false ) {
   223     if( !sk2.isEmpty() ) {
   202         HbAction *secondary = new HbAction( sk2 );
   224         HbAction *secondary = new HbAction( sk2 );
   203         cQuery->setSecondaryAction( secondary );
   225         cQuery->setSecondaryAction( secondary );
   204     }
   226     }
   205     HbAction* action = cQuery->exec();
   227 
   206     if( action == cQuery->secondaryAction() ){
   228 	HbAction* action = executeDialog( cQuery, associatedDrives );
       
   229     if( action == cQuery->primaryAction() ){
       
   230         ok = true;
       
   231     }
       
   232     else{
   207         ok = false;
   233         ok = false;
   208     }
       
   209     else{
       
   210         ok = true;
       
   211     }
   234     }
   212     if( ok )
   235     if( ok )
   213     {
   236     {
   214         QTime resultTime = cQuery->getTime();
   237         QTime resultTime = cQuery->getTime();
   215         if ( resultTime != time ){
   238         if ( resultTime != time ){
   218         }
   241         }
   219     }
   242     }
   220     delete cQuery;
   243     delete cQuery;
   221     return ret;
   244     return ret;
   222 }
   245 }
       
   246 
   223 bool FmDlgUtils::showTextQuery(
   247 bool FmDlgUtils::showTextQuery(
   224         const QString& title, QString& driveName )
   248         const QString& title, QString& text, bool isDimPrimaryActionWhenEmpty, int maxLength,
       
   249 		const QString &associatedDrives )
   225 {
   250 {
   226     bool ret( false );
   251     bool ret( false );
   227     bool ok ( true );                // SK return (out parameter)
   252     bool ok ( true );                // SK return (out parameter)
   228 
   253 
   229     FmSingleTextQuery *cQuery=new FmSingleTextQuery;
   254     FmSingleTextQuery::Options options( 0 );
   230     cQuery->setHeadingWidget( new HbLabel( title ) );
   255     if( isDimPrimaryActionWhenEmpty ) {
   231 
   256         options = FmSingleTextQuery::DimPrimereActionWhenEmpty;
   232     QString sk1 ( tr ( "ok" ) );
   257     }
   233     QString sk2 ( tr ( "cancel" ) );
   258     FmSingleTextQuery *cQuery = new FmSingleTextQuery( options );
   234 
   259     if( maxLength != -1 ){
   235     if(sk1.isEmpty() == false) {
   260         cQuery->setLineEditMaxLength( maxLength );
   236         HbAction *primary = new HbAction( sk1 );
   261     }
   237         cQuery->setPrimaryAction( primary );
   262     cQuery->setHeadingWidget( new HbLabel( title ) );
   238     }
   263 
   239 
   264     QString sk1 ( hbTrId ( "ok" ) );
   240     if( sk2.isEmpty() == false ) {
   265     QString sk2 ( hbTrId ( "cancel" ) );
   241         HbAction *secondary = new HbAction( sk2 );
   266 
   242         cQuery->setSecondaryAction( secondary );
   267     if( !sk1.isEmpty() ) {
   243     }
   268         HbAction *primary = new HbAction( sk1 );
   244     cQuery->setLineEditText( driveName );
   269         cQuery->setPrimaryAction( primary );
       
   270     }
       
   271 
       
   272     if( !sk2.isEmpty() ) {
       
   273         HbAction *secondary = new HbAction( sk2 );
       
   274         cQuery->setSecondaryAction( secondary );
       
   275     }
       
   276     cQuery->setLineEditText( text );
   245     cQuery->checkActions();
   277     cQuery->checkActions();
   246     
   278     
   247     HbAction* action = cQuery->exec();
   279 	HbAction* action = executeDialog( cQuery, associatedDrives );
   248     if( action == cQuery->secondaryAction() ){
   280     if( action == cQuery->primaryAction() ){
       
   281         ok = true;
       
   282     }
       
   283     else{
   249         ok = false;
   284         ok = false;
   250     }
       
   251     else{
       
   252         ok = true;
       
   253     }
   285     }
   254 
   286 
   255     if( ok ){
   287     if( ok ){
   256         QString newName = cQuery->getLineEditText();
   288         QString newName = cQuery->getLineEditText();
   257         if ( newName != driveName ){
   289         if ( newName != text ){
   258             driveName = newName;
   290             text = newName;
   259             ret = true;
   291             ret = true;
   260         }
   292         }
   261     }
   293     }
   262     delete cQuery;
   294     delete cQuery;
   263     return ret;
   295     return ret;
   264 }
   296 }
   265 
   297 
   266 bool FmDlgUtils::showConfirmPasswordQuery(
   298 bool FmDlgUtils::showSinglePasswordQuery( const QString &title, QString &pwd, const QString &associatedDrives )
   267         const QString &title, const QString &driveName, QString &pwd )
   299 {
   268 {
   300     bool ret( false );
   269     bool ret( false );
   301 
   270     bool ok ( true );               // SK return (out parameter)
   302     FmSingleTextQuery *cQuery = new FmSingleTextQuery( FmSingleTextQuery::DimPrimereActionWhenEmpty,
   271 
   303             HbLineEdit::Password );
   272     FmSingleTextQuery *cQuery = new FmSingleTextQuery( HbLineEdit::Password );
       
   273     cQuery->setHeadingWidget( new HbLabel( title ) );
   304     cQuery->setHeadingWidget( new HbLabel( title ) );
   274 
   305 
   275     QString sk1 ( tr ("ok" ) );
   306     QString sk1 ( tr ("ok" ) );
   276     QString sk2 ( tr ("cancel" ) );
   307     QString sk2 ( tr ("cancel" ) );
   277 
   308 
   278     if(sk1.isEmpty() == false) {
   309     if( !sk1.isEmpty() ) {
   279         HbAction *primary = new HbAction( sk1 );
   310         HbAction *primary = new HbAction( sk1 );
   280         cQuery->setPrimaryAction( primary );
   311         cQuery->setPrimaryAction( primary );
   281     }
   312     }
   282 
   313 
   283     if( sk2.isEmpty() == false ) {
   314     if( !sk2.isEmpty() ) {
   284         HbAction *secondary = new HbAction( sk2 );
   315         HbAction *secondary = new HbAction( sk2 );
   285         cQuery->setSecondaryAction( secondary );
   316         cQuery->setSecondaryAction( secondary );
   286     }
   317     }
   287     cQuery->checkActions();
   318     cQuery->checkActions();
   288     HbAction* action = 0;
   319 
   289     
   320     HbAction* action = executeDialog( cQuery, associatedDrives );
   290     bool pwdOk( false );
   321     if( action == cQuery->primaryAction() ){
   291     
   322         ret = true;
   292     while( ok && !pwdOk ){
   323         pwd = cQuery->getLineEditText();
   293         action = cQuery->exec();
   324     }
   294         if( action == cQuery->secondaryAction() ){
   325     else{
   295             ok = false;
   326         ret = false;
   296         }
   327     }
   297         else{
   328 
   298             ok = true;
   329     delete cQuery;
   299         }
   330     return ret;
   300 
   331 }
   301         if( ok ){
   332 
   302             QString inputPwd = cQuery->getLineEditText();
   333 bool FmDlgUtils::showMultiPasswordQuery(     
   303             if ( FmUtils::setDrivePwd( driveName, inputPwd, inputPwd ) == 0 ){
   334    const QString &firstLabel, const QString &secondLabel, QString &pwd, const QString &associatedDrives )
   304                 pwd = inputPwd;
   335 {
   305                 pwdOk = true;
   336     bool ret( false );
   306                 ret = true;
       
   307             }
       
   308             else{
       
   309                 HbMessageBox::information( tr( "The password is incorrect, try again!" ) );
       
   310             }
       
   311          }
       
   312     }
       
   313     delete cQuery;
       
   314     return ret;
       
   315 }
       
   316 
       
   317 bool FmDlgUtils::showChangePasswordQuery(     
       
   318        const QString &firstLabel, const QString &secondLabel, QString& newPassword )
       
   319 {
       
   320     bool ret( false );
       
   321     bool ok ( true );                // SK return (out parameter)
       
   322 
   337 
   323     FmMultiTextQuery *cQuery = new FmMultiTextQuery( HbLineEdit::Password );
   338     FmMultiTextQuery *cQuery = new FmMultiTextQuery( HbLineEdit::Password );
   324     cQuery->setFirstLabelText( firstLabel );
   339     cQuery->setFirstLabelText( firstLabel );
   325     cQuery->setSecondLabelText( secondLabel );
   340     cQuery->setSecondLabelText( secondLabel );
   326 
   341 
   327     QString sk1 = ( tr( "ok" ) );
   342     QString sk1 = ( hbTrId( "ok" ) );
   328     QString sk2 = ( tr( "cancel" ) );
   343     QString sk2 = ( hbTrId( "cancel" ) );
   329 
   344 
   330     if(sk1.isEmpty() == false) {
   345     if( !sk1.isEmpty() ) {
   331         HbAction *primary = new HbAction( sk1 );
   346         HbAction *primary = new HbAction( sk1 );
   332         cQuery->setPrimaryAction( primary );
   347         cQuery->setPrimaryAction( primary );
   333     }
   348     }
   334 
   349 
   335     if( sk2.isEmpty() == false ) {
   350     if( !sk2.isEmpty() ) {
   336         HbAction *secondary = new HbAction( sk2 );
   351         HbAction *secondary = new HbAction( sk2 );
   337         cQuery->setSecondaryAction( secondary );
   352         cQuery->setSecondaryAction( secondary );
   338     }
   353     }
   339     cQuery->checkActions();
   354     cQuery->checkActions();
   340     HbAction* action = 0;
       
   341     
   355     
   342     bool pwdOk( false );
   356 	HbAction* action = executeDialog( cQuery, associatedDrives );
   343     
   357     if( action == cQuery->primaryAction() ){
   344     while( ok && !pwdOk ){
   358         QString firstPwd = cQuery->getFirstEditText();
   345         action = cQuery->exec();
   359         QString secondPwd = cQuery->getSecondEditText();
   346         if( action == cQuery->secondaryAction() ){
   360         if ( firstPwd == secondPwd ){
   347             ok = false;
   361             pwd = secondPwd;
   348         }
   362             ret = true;
   349         else{
   363         }
   350             ok = true;
   364     }
   351         }
   365     else{
   352 
   366         ret = false;
   353         if( ok ){
   367     }
   354             QString firstPwd = cQuery->getFirstEditText();
   368 
   355             QString secondPwd = cQuery->getSecondEditText();
   369     delete cQuery;
   356             if ( firstPwd == secondPwd ){
   370     return ret;
   357                 newPassword = secondPwd;
   371 }
   358                 pwdOk = true;
       
   359                 ret = true;
       
   360             }
       
   361             else{
       
   362                 HbMessageBox::information( tr( "The passwords do not match, try again!" ) );
       
   363             }
       
   364          }
       
   365     }
       
   366     delete cQuery;
       
   367     return ret;
       
   368 }