~rpadovani/reminders-app/fixForReload

« back to all changes in this revision

Viewing changes to src/plugin/Evernote/notebooks.cpp

  • Committer: Michael Zanetti
  • Date: 2013-11-21 23:30:15 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: michael.zanetti@canonical.com-20131121233015-fnbjnzcb6chdtdzm
add libthrift, evernote-sdk and a Evernote qml plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "notebooks.h"
 
2
 
 
3
#include <QDebug>
 
4
 
 
5
Notebooks::Notebooks(QObject *parent) :
 
6
    QAbstractListModel(parent)
 
7
{
 
8
}
 
9
 
 
10
QVariant Notebooks::data(const QModelIndex &index, int role) const
 
11
{
 
12
    switch(role) {
 
13
    case RoleGuid:
 
14
        return QString::fromStdString(m_list.at(index.row()).guid);
 
15
    case RoleName:
 
16
        return QString::fromStdString(m_list.at(index.row()).name);
 
17
    }
 
18
 
 
19
    return QVariant();
 
20
}
 
21
 
 
22
int Notebooks::rowCount(const QModelIndex &parent) const
 
23
{
 
24
    return m_list.size();
 
25
}
 
26
 
 
27
QHash<int, QByteArray> Notebooks::roleNames() const
 
28
{
 
29
    QHash<int, QByteArray> roles;
 
30
    roles.insert(RoleGuid, "guid");
 
31
    roles.insert(RoleName, "name");
 
32
    return roles;
 
33
}
 
34
 
 
35
void Notebooks::refresh()
 
36
{
 
37
 
 
38
    QString token = NotesStore::instance()->token();
 
39
    if (token.isEmpty()) {
 
40
        qDebug() << "No token set. Cannot fetch notebooks.";
 
41
        return;
 
42
    }
 
43
 
 
44
    beginResetModel();
 
45
    try {
 
46
        NotesStore::instance()->evernoteNotesStoreClient()->listNotebooks(m_list, token.toStdString());
 
47
    } catch(...) {
 
48
        qDebug() << "Error fetching notebooks.";
 
49
//        displayException();
 
50
    }
 
51
 
 
52
    endResetModel();
 
53
 
 
54
//    for (int i = 0; i < notebooks.size(); ++i) {
 
55
//        qDebug() << "got notebooks" << QString::fromStdString(notebooks.at(i).name) << QString::fromStdString(notebooks.at(i).name)
 
56
//                 << QString::fromStdString(notebooks.at(i).guid);
 
57
//    }
 
58
}