controlpanel/src/cpframework/src/cputility.cpp
branchRCL_3
changeset 54 7e0eff37aedb
parent 53 8ee96d21d9bf
child 57 e78c61e77b1a
equal deleted inserted replaced
53:8ee96d21d9bf 54:7e0eff37aedb
     1 /*
       
     2 * Copyright (c) 2009 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:  Utility class for cpframework.
       
    15 *
       
    16 */
       
    17 #include "cputility.h"
       
    18 #include <QString>
       
    19 #include <QDir>
       
    20 #include <QFileInfo>
       
    21 #include <cpbasepath.h>
       
    22 #include <cppluginloader.h>
       
    23 #include <cpplugininterface.h>
       
    24 #include <cplogger.h>
       
    25 
       
    26 
       
    27 QStringList CpUtility::drives()
       
    28 {
       
    29 	static QStringList drives;
       
    30 
       
    31 	if (drives.empty()) {
       
    32         CPFW_LOG("device drives:");
       
    33 #ifdef WIN32
       
    34 		drives.append("C:");
       
    35         CPFW_LOG("C:");
       
    36 #else
       
    37 		QFileInfoList fileInfoList = QDir::drives();
       
    38 		foreach(const QFileInfo &fileInfo,fileInfoList) {
       
    39 			QString str = fileInfo.filePath();
       
    40 			if (str.length() > 2) {
       
    41 				str = str.left(2);
       
    42 			}
       
    43 			drives.append(str);
       
    44             CPFW_LOG(str);
       
    45 		}
       
    46 #endif  
       
    47 	}
       
    48 
       
    49 	return drives;
       
    50 }
       
    51 
       
    52 static QStringList directoriesFromAllDrives(const QString &baseDir)
       
    53 {
       
    54 	QStringList dirs;
       
    55 
       
    56 	QStringList drives = CpUtility::drives();
       
    57 	foreach(const QString &drive,drives) {
       
    58 		QString dir = drive + baseDir + QDir::separator();
       
    59 		if (QFileInfo(dir).exists()) {
       
    60 			dirs.append(dir);
       
    61             CPFW_LOG(dir);
       
    62 		}
       
    63 	}
       
    64 
       
    65 	return dirs;
       
    66 }
       
    67 
       
    68 QStringList CpUtility::pluginDirectories()
       
    69 {
       
    70 	static QStringList dirs;
       
    71 	if (dirs.empty()) {
       
    72         CPFW_LOG("ControlPanel plugin derectories:")
       
    73 		dirs = directoriesFromAllDrives(CP_PLUGIN_PATH);
       
    74 	}
       
    75 	return dirs;
       
    76 }
       
    77 
       
    78 QStringList CpUtility::configFileDirectories()
       
    79 {
       
    80 	static QStringList dirs;
       
    81 	if (dirs.empty()) {
       
    82         CPFW_LOG("ControlPanel configuration file derectories:");
       
    83 		dirs = directoriesFromAllDrives(CP_PLUGIN_CONFIG_PATH);
       
    84 	}
       
    85 	return dirs;
       
    86 }
       
    87