Changeset View
Changeset View
Standalone View
Standalone View
src/upload/atticahelper.cpp
Show All 35 Lines | 35 | { | |||
---|---|---|---|---|---|
36 | connect(&providerManager, &Attica::ProviderManager::defaultProvidersLoaded, this, &AtticaHelper::defaultProvidersLoaded); | 36 | connect(&providerManager, &Attica::ProviderManager::defaultProvidersLoaded, this, &AtticaHelper::defaultProvidersLoaded); | ||
37 | providerManager.loadDefaultProviders(); | 37 | providerManager.loadDefaultProviders(); | ||
38 | } | 38 | } | ||
39 | 39 | | |||
40 | void AtticaHelper::addProviderFile(const QUrl &file) | 40 | void AtticaHelper::addProviderFile(const QUrl &file) | ||
41 | { | 41 | { | ||
42 | if (! providerManager.providerFiles().contains(file)) { | 42 | if (! providerManager.providerFiles().contains(file)) { | ||
43 | // If a custom provider file is added, remove all the default ones. | 43 | // If a custom provider file is added, remove all the default ones. | ||
44 | foreach (const QUrl &url, providerManager.defaultProviderFiles()) { | 44 | const auto lstUrl = providerManager.defaultProviderFiles(); | ||
45 | for (const QUrl &url : lstUrl) { | ||||
45 | providerManager.removeProviderFileFromDefaultProviders(url); | 46 | providerManager.removeProviderFileFromDefaultProviders(url); | ||
46 | } | 47 | } | ||
47 | providerManager.addProviderFile(file); | 48 | providerManager.addProviderFile(file); | ||
48 | } | 49 | } | ||
49 | } | 50 | } | ||
50 | 51 | | |||
51 | void AtticaHelper::defaultProvidersLoaded() | 52 | void AtticaHelper::defaultProvidersLoaded() | ||
52 | { | 53 | { | ||
53 | QStringList providers; | 54 | QStringList providers; | ||
54 | foreach (const Attica::Provider &p, providerManager.providers()) { | 55 | const auto lst = providerManager.providers(); | ||
56 | for (const Attica::Provider &p : lst) { | ||||
55 | if (p.isEnabled()) { | 57 | if (p.isEnabled()) { | ||
56 | providers.append(p.name()); | 58 | providers.append(p.name()); | ||
57 | } | 59 | } | ||
58 | } | 60 | } | ||
59 | emit providersLoaded(providers); | 61 | emit providersLoaded(providers); | ||
60 | } | 62 | } | ||
61 | 63 | | |||
62 | void AtticaHelper::setCurrentProvider(const QString &provider) | 64 | void AtticaHelper::setCurrentProvider(const QString &provider) | ||
63 | { | 65 | { | ||
64 | foreach (const Attica::Provider &p, providerManager.providers()) { | 66 | const auto lst = providerManager.providers(); | ||
67 | for (const Attica::Provider &p : lst) { | ||||
65 | if (p.name() == provider) { | 68 | if (p.name() == provider) { | ||
66 | currentProvider = p; | 69 | currentProvider = p; | ||
67 | break; | 70 | break; | ||
68 | } | 71 | } | ||
69 | } | 72 | } | ||
70 | } | 73 | } | ||
71 | 74 | | |||
72 | Attica::Provider AtticaHelper::provider() | 75 | Attica::Provider AtticaHelper::provider() | ||
Show All 36 Lines | 109 | { | |||
109 | connect(job, &Attica::ListJob<Attica::Category>::finished, | 112 | connect(job, &Attica::ListJob<Attica::Category>::finished, | ||
110 | this, static_cast<void(AtticaHelper::*)(Attica::BaseJob*)>(&AtticaHelper::categoriesLoaded)); | 113 | this, static_cast<void(AtticaHelper::*)(Attica::BaseJob*)>(&AtticaHelper::categoriesLoaded)); | ||
111 | job->start(); | 114 | job->start(); | ||
112 | } | 115 | } | ||
113 | 116 | | |||
114 | void AtticaHelper::categoriesLoaded(Attica::BaseJob *baseJob) | 117 | void AtticaHelper::categoriesLoaded(Attica::BaseJob *baseJob) | ||
115 | { | 118 | { | ||
116 | Attica::ListJob<Attica::Category> *listJob = static_cast<Attica::ListJob<Attica::Category>*>(baseJob); | 119 | Attica::ListJob<Attica::Category> *listJob = static_cast<Attica::ListJob<Attica::Category>*>(baseJob); | ||
117 | Attica::Category::List newCategories = listJob->itemList(); | 120 | const Attica::Category::List newCategories = listJob->itemList(); | ||
118 | 121 | | |||
119 | if (m_configuredCategories.isEmpty()) { | 122 | if (m_configuredCategories.isEmpty()) { | ||
120 | qWarning() << "No category was set in knsrc file. Adding all categories."; | 123 | qWarning() << "No category was set in knsrc file. Adding all categories."; | ||
121 | Q_FOREACH (const Attica::Category &category, newCategories) { | 124 | for (const Attica::Category &category : newCategories) { | ||
122 | m_validCategories.append(category); | 125 | m_validCategories.append(category); | ||
123 | } | 126 | } | ||
124 | } else { | 127 | } else { | ||
125 | Q_FOREACH (const Attica::Category &category, newCategories) { | 128 | for (const Attica::Category &category : newCategories) { | ||
126 | if (m_configuredCategories.contains(category.name())) { | 129 | if (m_configuredCategories.contains(category.name())) { | ||
127 | m_validCategories.append(category); | 130 | m_validCategories.append(category); | ||
128 | } | 131 | } | ||
129 | } | 132 | } | ||
130 | } | 133 | } | ||
131 | emit categoriesLoaded(m_validCategories); | 134 | emit categoriesLoaded(m_validCategories); | ||
132 | } | 135 | } | ||
133 | 136 | | |||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |