~mkas/mixxx/mysql

« back to all changes in this revision

Viewing changes to mixxx/src/library/setlogfeature.cpp

  • Committer: MKas
  • Date: 2012-11-03 12:55:54 UTC
  • Revision ID: mkas@tux.lt-20121103125554-ez5ajqyk7bwehrp2
merge with trunk + sql fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include "controlobject.h"
11
11
#include "library/playlisttablemodel.h"
12
12
#include "library/trackcollection.h"
 
13
#include "library/treeitem.h"
13
14
#include "playerinfo.h"
14
 
#include "treeitem.h"
 
15
 
15
16
 
16
17
SetlogFeature::SetlogFeature(QObject* parent,
17
18
                             ConfigObject<ConfigValue>* pConfig,
47
48
        qDebug() << "An unknown error occurred while creating playlist: " << set_log_name;
48
49
    }
49
50
 
50
 
    // Setup the sidebar playlist model
51
 
    m_playlistTableModel.setTable("Playlists");
52
 
    m_playlistTableModel.setFilter("hidden=2"); // PLHT_SET_LOG
53
 
    m_playlistTableModel.setSort(m_playlistTableModel.fieldIndex("id"),
54
 
                                 Qt::AscendingOrder);
55
 
    m_playlistTableModel.select();
56
 
 
57
51
    //construct child model
58
52
    TreeItem *rootItem = new TreeItem();
59
53
    m_childModel.setRootItem(rootItem);
61
55
}
62
56
 
63
57
SetlogFeature::~SetlogFeature() {
 
58
    // If the history playlist we created doesn't have any tracks in it then
 
59
    // delete it so we don't end up with tons of empty playlists. This is mostly
 
60
    // for developers since they regularly open Mixxx without loading a track.
 
61
    if (m_playlistId != -1 &&
 
62
        m_playlistDao.tracksInPlaylist(m_playlistId) == 0) {
 
63
        m_playlistDao.deletePlaylist(m_playlistId);
 
64
    }
64
65
}
65
66
 
66
67
QVariant SetlogFeature::title() {
127
128
    menu.exec(globalPos);
128
129
}
129
130
 
130
 
bool SetlogFeature::dropAcceptChild(const QModelIndex& index, QUrl url){
131
 
    Q_UNUSED(url);
 
131
bool SetlogFeature::dropAcceptChild(const QModelIndex& index, QList<QUrl> urls){
 
132
    Q_UNUSED(urls);
132
133
    Q_UNUSED(index);
133
134
    return false;
134
135
}
139
140
    return false;
140
141
}
141
142
 
142
 
/**
143
 
  * Purpose: When inserting or removing playlists,
144
 
  * we require the sidebar model not to reset.
145
 
  * This method queries the database and does dynamic insertion
146
 
*/
147
 
QModelIndex SetlogFeature::constructChildModel(int selected_id)
148
 
{
149
 
    QList<TreeItem*> data_list;
150
 
    int nameColumn = m_playlistTableModel.record().indexOf("name");
151
 
    int idColumn = m_playlistTableModel.record().indexOf("id");
152
 
    int selected_row = -1;
153
 
    // Access the invisible root item
154
 
    TreeItem* root = m_childModel.getItem(QModelIndex());
155
 
 
156
 
    // Create new TreeItems for the playlists in the database
157
 
    for (int row = 0; row < m_playlistTableModel.rowCount(); ++row) {
158
 
        QModelIndex ind = m_playlistTableModel.index(row, nameColumn);
159
 
        QString playlist_name = m_playlistTableModel.data(ind).toString();
160
 
        ind = m_playlistTableModel.index(row, idColumn);
161
 
        int playlist_id = m_playlistTableModel.data(ind).toInt();
162
 
 
163
 
        if ( selected_id == playlist_id) {
164
 
            // save index for selection
165
 
            selected_row = row;
166
 
        }
167
 
 
168
 
        // Create the TreeItem whose parent is the invisible root item
169
 
        TreeItem* item = new TreeItem(playlist_name, playlist_name, this, root);
170
 
        if (playlist_id == m_playlistId) {
171
 
            item->setIcon(QIcon(":/images/library/ic_library_history_current.png"));
172
 
        } else if (m_playlistDao.isPlaylistLocked(playlist_id)) {
173
 
            item->setIcon(QIcon(":/images/library/ic_library_locked.png"));
174
 
        } else {
175
 
            item->setIcon(QIcon());
176
 
        }
177
 
        data_list.append(item);
178
 
    }
179
 
 
180
 
    // Append all the newly created TreeItems in a dynamic way to the childmodel
181
 
    m_childModel.insertRows(data_list, 0, m_playlistTableModel.rowCount());
182
 
    if (selected_row == -1) {
183
 
        return QModelIndex();
184
 
    }
185
 
    return m_childModel.index(selected_row, 0);
 
143
void SetlogFeature::buildPlaylistList() {
 
144
    m_playlistList.clear();
 
145
    // Setup the sidebar playlist model
 
146
    QSqlTableModel playlistTableModel(this, m_pTrackCollection->getDatabase());
 
147
    playlistTableModel.setTable("Playlists");
 
148
    playlistTableModel.setFilter("hidden=2"); // PLHT_SET_LOG
 
149
    playlistTableModel.setSort(playlistTableModel.fieldIndex("id"),
 
150
                               Qt::AscendingOrder);
 
151
    playlistTableModel.select();
 
152
    while (playlistTableModel.canFetchMore()) {
 
153
        playlistTableModel.fetchMore();
 
154
    }
 
155
    int nameColumn = playlistTableModel.record().indexOf("name");
 
156
    int idColumn = playlistTableModel.record().indexOf("id");
 
157
 
 
158
    for (int row = 0; row < playlistTableModel.rowCount(); ++row) {
 
159
        int id = playlistTableModel.data(
 
160
            playlistTableModel.index(row, idColumn)).toInt();
 
161
        QString name = playlistTableModel.data(
 
162
            playlistTableModel.index(row, nameColumn)).toString();
 
163
        m_playlistList.append(qMakePair(id, name));
 
164
    }
 
165
}
 
166
 
 
167
void SetlogFeature::decorateChild(TreeItem* item, int playlist_id) {
 
168
    if (playlist_id == m_playlistId) {
 
169
        item->setIcon(QIcon(":/images/library/ic_library_history_current.png"));
 
170
    } else if (m_playlistDao.isPlaylistLocked(playlist_id)) {
 
171
        item->setIcon(QIcon(":/images/library/ic_library_locked.png"));
 
172
    } else {
 
173
        item->setIcon(QIcon());
 
174
    }
186
175
}
187
176
 
188
177
void SetlogFeature::slotJoinWithPrevious() {
295
284
    if (type == PlaylistDAO::PLHT_SET_LOG ||
296
285
        type == PlaylistDAO::PLHT_UNKNOWN) { // In case of a deleted Playlist
297
286
        clearChildModel();
298
 
        m_playlistTableModel.select();
299
287
        m_lastRightClickedIndex = constructChildModel(playlistId);
300
288
 
301
289
        if (type != PlaylistDAO::PLHT_UNKNOWN) {