~elopio/gallery-app/revert_workaround-1302706-click_toolbar_button_failure

« back to all changes in this revision

Viewing changes to src/gallery-manager.cpp

  • Committer: Leo Arias
  • Date: 2015-05-15 08:05:23 UTC
  • mfrom: (954.1.241 gallery-app)
  • Revision ID: leo.arias@canonical.com-20150515080523-i2of3vr8h7dioj59
Now the toolbar object is not needed at all.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "media-monitor.h"
38
38
 
39
39
// qml
40
 
#include "gallery-standard-image-provider.h"
41
40
#include "qml-media-collection-model.h"
42
41
 
43
42
// util
53
52
/*!
54
53
 * \brief GalleryManager::GalleryManager
55
54
 * \param picturesDir
56
 
 * \param view
57
55
 * \param logImageLoading
58
56
 */
59
57
GalleryManager::GalleryManager(bool desktopMode,
60
 
                               const QString& picturesDir,
61
 
                               QQuickView *view)
 
58
                               const QString& picturesDir)
62
59
    : collectionsInitialised(false),
63
 
      m_resource(new Resource(desktopMode, picturesDir, view)),
64
 
      m_standardImageProvider(new GalleryStandardImageProvider()),
 
60
      m_resource(new Resource(desktopMode, picturesDir)),
65
61
      m_database(0),
66
62
      m_defaultTemplate(0),
67
63
      m_mediaCollection(0),
71
67
      m_desktopMode(desktopMode),
72
68
      m_mediaLibrary(0)
73
69
{
74
 
    const int maxTextureSize = m_resource->maxTextureSize();
75
 
    m_standardImageProvider->setMaxLoadResolution(maxTextureSize);
76
70
    m_mediaFactory = new MediaObjectFactory(m_desktopMode, m_resource);
77
71
 
 
72
    QObject::connect(m_mediaFactory, SIGNAL(mediaObjectCreated(MediaSource*)),
 
73
                     this, SLOT(onMediaObjectCreated(MediaSource*)));
 
74
    QObject::connect(m_mediaFactory, SIGNAL(mediaFromDBLoaded(QSet<DataObject *>)),
 
75
                     this, SLOT(onMediaFromDBLoaded(QSet<DataObject *>)));
 
76
 
 
77
 
78
78
    m_galleryManager = this;
79
79
}
80
80
 
92
92
    delete m_defaultTemplate;
93
93
    delete m_resource;
94
94
    delete m_mediaCollection;
95
 
    delete m_standardImageProvider;
96
95
}
97
96
 
98
97
/*!
99
98
 * \brief GalleryManager::instance
100
99
 * \param application_path_dir the directory of where the executable is
101
100
 * \param picturesDir the directory of the images
102
 
 * \param view the view is used to determine the max texture size
103
101
 * \param logImageLoading if true, the image loadings times are printed to stdout
104
102
 * \return
105
103
 */
141
139
        m_defaultTemplate = new AlbumDefaultTemplate();
142
140
        m_mediaCollection = new MediaCollection(m_database->getMediaTable());
143
141
 
 
142
        QObject::connect(m_mediaCollection, SIGNAL(collectionChanged()),
 
143
                      this, SIGNAL(collectionChanged()));
 
144
 
144
145
        fillMediaCollection();
145
 
        startFileMonitoring();
146
146
 
147
147
        collectionsInitialised = true;
148
148
 
181
181
        // media found
182
182
        QObject::connect(
183
183
                    m_mediaCollection,
184
 
                    SIGNAL(contentsChanged(const QSet<DataObject*>*,const QSet<DataObject*>*)),
 
184
                    SIGNAL(contentsChanged(const QSet<DataObject*>*,const QSet<DataObject*>*, bool)),
185
185
                    m_eventCollection,
186
 
                    SLOT(onMediaAddedRemoved(const QSet<DataObject*>*,const QSet<DataObject*>*)));
 
186
                    SLOT(onMediaAddedRemoved(const QSet<DataObject*>*,const QSet<DataObject*>*, bool)));
187
187
        // seed what's already present
188
 
        m_eventCollection->onMediaAddedRemoved(&(m_mediaCollection->getAsSet()), NULL);
 
188
        m_eventCollection->onMediaAddedRemoved(&(m_mediaCollection->getAsSet()), NULL, true);
189
189
    }
190
190
 
191
191
    return m_eventCollection;
207
207
}
208
208
 
209
209
/*!
210
 
 * \brief GalleryManager::logImageLoading enabled or disbaled logging image load
211
 
 * times to stdout
212
 
 * \param log
213
 
 */
214
 
void GalleryManager::logImageLoading(bool log)
215
 
{
216
 
    m_standardImageProvider->setLogging(log);
217
 
}
218
 
 
219
 
/*!
220
210
 * \brief GalleryManager::fillMediaCollection fills the MediaCollection with
221
211
 * the content of the picture directory
222
212
 */
223
213
void GalleryManager::fillMediaCollection()
224
214
{
225
215
    Q_ASSERT(m_mediaCollection);
226
 
 
227
 
    QSet<DataObject*> medias;
228
 
    medias = m_mediaFactory->mediasFromDB();
229
 
    m_mediaCollection->addMany(medias);
230
 
    m_mediaFactory->clear();
 
216
    m_mediaFactory->loadMediaFromDB();
231
217
}
232
218
 
233
219
/*!
242
228
    m_monitor = new MediaMonitor();
243
229
    QObject::connect(m_mediaCollection, SIGNAL(mediaIsBusy(bool)),
244
230
                     m_monitor, SLOT(setMonitoringOnHold(bool)));
245
 
    QObject::connect(m_monitor, SIGNAL(mediaItemAdded(QString)),
246
 
                     this, SLOT(onMediaItemAdded(QString)));
 
231
    QObject::connect(m_monitor, SIGNAL(mediaItemAdded(QString, int)),
 
232
                     this, SLOT(onMediaItemAdded(QString, int)));
247
233
    QObject::connect(m_monitor, SIGNAL(mediaItemRemoved(qint64)),
248
234
                     this, SLOT(onMediaItemRemoved(qint64)));
 
235
    QObject::connect(m_monitor, SIGNAL(consistencyCheckFinished()),
 
236
                     this, SIGNAL(consistencyCheckFinished()));
249
237
 
250
238
    m_monitor->startMonitoring(m_resource->mediaDirectories());
251
239
    m_monitor->checkConsistency(m_mediaCollection);
255
243
 * \brief GalleryApplication::onMediaItemAdded
256
244
 * \param file
257
245
 */
258
 
void GalleryManager::onMediaItemAdded(QString file)
 
246
void GalleryManager::onMediaItemAdded(QString file, int priority)
259
247
{
260
248
    if (! m_mediaCollection->containsFile(file)) {
261
249
        QFileInfo fi(file);
262
 
        MediaSource *media = m_mediaFactory->create(fi, m_desktopMode, m_resource);
263
 
 
264
 
        if (media)
265
 
            m_mediaCollection->add(media);
 
250
        m_mediaFactory->create(fi, priority, m_desktopMode, m_resource);
266
251
    }
267
252
}
268
253
 
276
261
}
277
262
 
278
263
/*!
279
 
 * \brief GalleryManager::takeGalleryStandardImageProvider returns the standard image provider
280
 
 * and gives up the owndership 
281
 
 */
282
 
GalleryStandardImageProvider* GalleryManager::takeGalleryStandardImageProvider()
283
 
{
284
 
    GalleryStandardImageProvider *provider = m_standardImageProvider;
285
 
    m_standardImageProvider = 0;
286
 
    return provider;
 
264
 * \brief GalleryManager::onMediaObjectCreated
 
265
 * \param mediaObject
 
266
 */
 
267
void GalleryManager::onMediaObjectCreated(MediaSource *mediaObject)
 
268
{
 
269
    m_mediaCollection->add(mediaObject);
 
270
}
 
271
 
 
272
/*!
 
273
 * \brief GalleryManager::onMediaFromDBLoaded
 
274
 * \param mediaFromDB
 
275
 */
 
276
void GalleryManager::onMediaFromDBLoaded(QSet<DataObject *> mediaFromDB)
 
277
{
 
278
    m_mediaCollection->addMany(mediaFromDB);
 
279
    m_mediaFactory->clear();
 
280
 
 
281
    startFileMonitoring();
287
282
}