File: owncloudsync.cpp

package info (click to toggle)
lomiri-cloudsync-app 0.8.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,560 kB
  • sloc: cpp: 1,053; python: 67; javascript: 25; makefile: 21; sh: 9
file content (129 lines) | stat: -rw-r--r-- 3,717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "owncloudsync.h"

#include <QDir>
#include <QDebug>
#include <QStandardPaths>
#include <QCoreApplication>
#include <QNetworkConfigurationManager>


OwncloudSync::OwncloudSync(QObject *parent) : QObject(parent)
{

}

QString OwncloudSync::homePath(){

    return QDir::homePath();
}

QVariantList OwncloudSync::logPath(){

    QString logPath;

    logPath = homePath();
    logPath.append("/.cache/upstart/");

    QDir logFiles(logPath);

    //To Do: get entrylists for each log sorted by most recent.
    QStringList filters;
    filters << "owncloud-sync.log.1.gz" << "OwncloudSyncd.log";
    logFiles.setNameFilters(filters);
    //logFiles.setSorting(QDir::Time);

    QStringList logs = logFiles.entryList(QDir::NoDotAndDotDot | QDir::NoSymLinks | QDir::Files);
    QList<QVariant> variantlist;

    foreach(QString log, logs){
        log.prepend(logPath);
        variantlist << QVariant(log);
    }

    return variantlist;
}


bool OwncloudSync::newFolder(QString folderPath)
{

    if(folderPath.startsWith("file://"))
        folderPath = folderPath.replace("file://", "");

    QString path = folderPath; //getHomePath() + "/" + "New Folder";
    //QString folder = "New Folder";
    //QString folderPath = path;
    QDir dir;
    int number = 0;

    while(QDir(folderPath).exists()){
        number++;
        folderPath = path + " " + QString::number(number);
    }

    dir.mkdir(folderPath);

    //  if (!dir.exists()) {
    //      dir.mkpath(folderPath);
    //  }


    qDebug() << "Create New Folder: " << folderPath;

    return true;

}

void OwncloudSync::removeAllConfigs()
{
    //qDebug() << "homePath" << QDir::homePath();
    //qDebug() << "GenericConfigLocation" << QStandardPaths::GenericConfigLocation;
    //qDebug() << "AppConfigLocation" << QStandardPaths::AppConfigLocation;
    //qDebug() << "writableLocation" << QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); // "/ubsync/owncloud-sync.conf";
    //qDebug() << "writableLocation" << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); // "/ubsync/Databases";
    //qDebug() << "applicationName" << QCoreApplication::applicationName();

    QString configPath = QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() +  QCoreApplication::applicationName());
    QString databasePath = QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QDir::separator() +  QCoreApplication::applicationName());

    qDebug() << "OwncloudSync::removeAllConfigs" << "configPath" << configPath;
    qDebug() << "OwncloudSync::removeAllConfigs" << "databasePath" << databasePath;

    deleteAll(configPath);
    deleteAll(databasePath);

}

void OwncloudSync::deleteAll(QString path)
{
    qDebug() << "OwncloudSync::deleteAll" << path;
    QDir dir(path);
    dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
    foreach(QString dirFile, dir.entryList())
    {
        qDebug() << "OwncloudSync::deleteAll - Delete:" << dirFile;

        QFileInfo dirFileInfo(path, dirFile);
        qDebug() << "OwncloudSync::deleteAll" << dirFileInfo.absoluteFilePath();

        if(dirFileInfo.isDir())
        {
            qDebug() << "OwncloudSync::deleteAll" << dirFile << "is a directory";
            deleteAll(dirFileInfo.absoluteFilePath());
        }else{
            dir.remove(dirFile);
        }
    }
}

bool OwncloudSync::networkAvailable(){

QNetworkConfigurationManager mgr;
qDebug() << "Network Connection Type: " << mgr.defaultConfiguration().bearerTypeName();

QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);

return activeConfigs.count();

}