emailservices/nmclientapi/src/nmapimailboxsettings_p.cpp
author hgs
Fri, 23 Jul 2010 19:09:50 +0300
changeset 56 15bc1d5d6267
parent 48 10eaf342f539
child 74 6c59112cfd31
permissions -rw-r--r--
201029
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description:
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    18
#include "nmapiheaders.h"
56
hgs
parents: 48
diff changeset
    19
#include <nmapisettingsmanager.h>
47
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
namespace EmailClientApi
hgs
parents:
diff changeset
    23
{
hgs
parents:
diff changeset
    24
NmApiMailboxSettingsPrivate::NmApiMailboxSettingsPrivate(QObject *parent) : 
hgs
parents:
diff changeset
    25
    QObject(parent), 
hgs
parents:
diff changeset
    26
    mFactory(NULL),
hgs
parents:
diff changeset
    27
    mDeleteMailboxOperation(NULL)
hgs
parents:
diff changeset
    28
{
hgs
parents:
diff changeset
    29
    NM_FUNCTION;
hgs
parents:
diff changeset
    30
    mFactory = NmApiDataPluginFactory::instance();
hgs
parents:
diff changeset
    31
    Q_CHECK_PTR(mFactory);
hgs
parents:
diff changeset
    32
}
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
NmApiMailboxSettingsPrivate::~NmApiMailboxSettingsPrivate()
hgs
parents:
diff changeset
    35
{
hgs
parents:
diff changeset
    36
    NM_FUNCTION;
hgs
parents:
diff changeset
    37
    NmApiDataPluginFactory::releaseInstance(mFactory);
hgs
parents:
diff changeset
    38
    if(mDeleteMailboxOperation && mDeleteMailboxOperation->isRunning()) {
hgs
parents:
diff changeset
    39
        mDeleteMailboxOperation->cancelOperation();        
hgs
parents:
diff changeset
    40
    }
hgs
parents:
diff changeset
    41
}
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
bool NmApiMailboxSettingsPrivate::listMailboxIds(QList<quint64> &idList)
hgs
parents:
diff changeset
    44
{
hgs
parents:
diff changeset
    45
    NM_FUNCTION; 
hgs
parents:
diff changeset
    46
    QList<NmId> mailboxIds;
hgs
parents:
diff changeset
    47
    bool ret = false;
hgs
parents:
diff changeset
    48
    idList.clear();
hgs
parents:
diff changeset
    49
    
hgs
parents:
diff changeset
    50
    NmDataPluginInterface *instance = mFactory->interfaceInstance();
hgs
parents:
diff changeset
    51
    if (instance) {
hgs
parents:
diff changeset
    52
        if (instance->listMailboxIds(mailboxIds) == KErrNone) {
hgs
parents:
diff changeset
    53
            
hgs
parents:
diff changeset
    54
            foreach (NmId boxId, mailboxIds) {
hgs
parents:
diff changeset
    55
                        idList.append(boxId.id());
hgs
parents:
diff changeset
    56
                    }
hgs
parents:
diff changeset
    57
            
hgs
parents:
diff changeset
    58
            ret = true;   
hgs
parents:
diff changeset
    59
            }
hgs
parents:
diff changeset
    60
        } 
hgs
parents:
diff changeset
    61
     
hgs
parents:
diff changeset
    62
    return ret;
hgs
parents:
diff changeset
    63
}
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
bool NmApiMailboxSettingsPrivate::loadSettings(quint64 mailboxId, NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    66
{
hgs
parents:
diff changeset
    67
    NM_FUNCTION;
56
hgs
parents: 48
diff changeset
    68
    QScopedPointer<NmApiSettingsManager> settingsManager(new NmApiSettingsManager(mailboxId));  
hgs
parents: 48
diff changeset
    69
    return settingsManager->load(mailboxId, data);
47
hgs
parents:
diff changeset
    70
}
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
bool NmApiMailboxSettingsPrivate::saveSettings(const NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    73
{
hgs
parents:
diff changeset
    74
    NM_FUNCTION;
56
hgs
parents: 48
diff changeset
    75
    QScopedPointer<NmApiSettingsManager> settingsManager(new NmApiSettingsManager(data.mailboxId()));  
hgs
parents: 48
diff changeset
    76
    return settingsManager->save(data);
47
hgs
parents:
diff changeset
    77
}
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
bool NmApiMailboxSettingsPrivate::createMailbox(
hgs
parents:
diff changeset
    80
    const QString &mailboxType,
hgs
parents:
diff changeset
    81
    NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    82
{
hgs
parents:
diff changeset
    83
    NM_FUNCTION;
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    84
    Q_UNUSED(mailboxType);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    85
    Q_UNUSED(data);
47
hgs
parents:
diff changeset
    86
    bool ret = false;
hgs
parents:
diff changeset
    87
    
hgs
parents:
diff changeset
    88
    /*QT_TRY {
hgs
parents:
diff changeset
    89
        if (mailboxType==NmApiMailboxTypePop || mailboxType==NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
    90
            QScopedPointer<NmApiPopImapSettingsManager> popImapManager(new NmApiPopImapSettingsManager());  
hgs
parents:
diff changeset
    91
            popImapManager->createMailbox(mailboxType, data);
hgs
parents:
diff changeset
    92
            ret = true;
hgs
parents:
diff changeset
    93
        }
hgs
parents:
diff changeset
    94
        else {
hgs
parents:
diff changeset
    95
            ret = false;
hgs
parents:
diff changeset
    96
        }
hgs
parents:
diff changeset
    97
        //TODO store cenrep stuff here
hgs
parents:
diff changeset
    98
    }
hgs
parents:
diff changeset
    99
    QT_CATCH(...){
hgs
parents:
diff changeset
   100
        ret = false;
hgs
parents:
diff changeset
   101
    }*/
hgs
parents:
diff changeset
   102
    
hgs
parents:
diff changeset
   103
    return ret;
hgs
parents:
diff changeset
   104
}
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
bool NmApiMailboxSettingsPrivate::deleteMailbox(quint64 mailboxId)
hgs
parents:
diff changeset
   107
{
hgs
parents:
diff changeset
   108
    NM_FUNCTION;
hgs
parents:
diff changeset
   109
    bool ret = false;
hgs
parents:
diff changeset
   110
    NmDataPluginInterface *instance = mFactory->interfaceInstance();
hgs
parents:
diff changeset
   111
    if (instance) {
hgs
parents:
diff changeset
   112
        if (mDeleteMailboxOperation && mDeleteMailboxOperation->isRunning()) {
hgs
parents:
diff changeset
   113
            mDeleteMailboxOperation->cancelOperation();
hgs
parents:
diff changeset
   114
        }
hgs
parents:
diff changeset
   115
        mDeleteMailboxOperation = instance->deleteMailboxById(NmId(mailboxId));
hgs
parents:
diff changeset
   116
        
hgs
parents:
diff changeset
   117
        if (mDeleteMailboxOperation) {
hgs
parents:
diff changeset
   118
            ret = true;
hgs
parents:
diff changeset
   119
            connect(mDeleteMailboxOperation, 
hgs
parents:
diff changeset
   120
                    SIGNAL(operationCompleted(int)), 
hgs
parents:
diff changeset
   121
                    this, 
hgs
parents:
diff changeset
   122
                    SIGNAL(mailboxDeleted(int)));
hgs
parents:
diff changeset
   123
        }
hgs
parents:
diff changeset
   124
    }
hgs
parents:
diff changeset
   125
    return ret;
hgs
parents:
diff changeset
   126
}
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
bool NmApiMailboxSettingsPrivate::populateDefaultSettings(
hgs
parents:
diff changeset
   129
    const QString &mailboxType, NmApiMailboxSettingsData &data) 
hgs
parents:
diff changeset
   130
{
hgs
parents:
diff changeset
   131
    NM_FUNCTION;
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   132
    Q_UNUSED(mailboxType);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   133
    Q_UNUSED(data);
47
hgs
parents:
diff changeset
   134
    /*QScopedPointer<NmApiPopImapSettingsManager> popImapManager(new NmApiPopImapSettingsManager());  
hgs
parents:
diff changeset
   135
    return popImapManager->populateDefaults(mailboxType, data);*/
hgs
parents:
diff changeset
   136
    return true;
hgs
parents:
diff changeset
   137
}
hgs
parents:
diff changeset
   138
hgs
parents:
diff changeset
   139
}// namespace