Commit cb019e29 authored by pvuorela's avatar pvuorela

Merge branch 'import_model_error_state' into 'master'

[nemo-qml-plugin-calendar] Add error state to import model. Contributes to JB#52653

See merge request !75
parents 314b49b2 e6e580e3
......@@ -46,7 +46,8 @@
#include <KCalendarCore/MemoryCalendar>
CalendarImportModel::CalendarImportModel(QObject *parent)
: QAbstractListModel(parent)
: QAbstractListModel(parent),
mError(false)
{
}
......@@ -90,6 +91,11 @@ void CalendarImportModel::setIcsString(const QString &icsData)
reload();
}
bool CalendarImportModel::error() const
{
return mError;
}
QObject *CalendarImportModel::getEvent(int index)
{
if (index < 0 || index >= mEventList.count())
......@@ -196,12 +202,14 @@ static bool incidenceLessThan(const KCalendarCore::Incidence::Ptr e1,
void CalendarImportModel::reload()
{
if (!mFileName.isEmpty() || !mIcsRawData.isEmpty()) {
importToMemory(mFileName, mIcsRawData);
bool success = importToMemory(mFileName, mIcsRawData);
setError(!success);
} else if (!mEventList.isEmpty()) {
beginResetModel();
mEventList.clear();
endResetModel();
emit countChanged();
setError(false);
}
}
......@@ -210,12 +218,14 @@ bool CalendarImportModel::importToMemory(const QString &fileName, const QByteArr
if (!mEventList.isEmpty())
mEventList.clear();
bool success = false;
beginResetModel();
KCalendarCore::MemoryCalendar::Ptr cal(new KCalendarCore::MemoryCalendar(QTimeZone::systemTimeZone()));
if (!fileName.isEmpty()) {
CalendarUtils::importFromFile(fileName, cal);
success = CalendarUtils::importFromFile(fileName, cal);
} else {
CalendarUtils::importFromIcsRawData(icsData, cal);
success = CalendarUtils::importFromIcsRawData(icsData, cal);
}
KCalendarCore::Incidence::List incidenceList = cal->incidences();
for (int i = 0; i < incidenceList.size(); i++) {
......@@ -228,6 +238,14 @@ bool CalendarImportModel::importToMemory(const QString &fileName, const QByteArr
endResetModel();
emit countChanged();
return true;
return success;
}
void CalendarImportModel::setError(bool error)
{
if (error != mError) {
mError = error;
emit errorChanged();
}
}
......@@ -44,6 +44,7 @@ class CalendarImportModel : public QAbstractListModel
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
Q_PROPERTY(QString icsString READ icsString WRITE setIcsString NOTIFY icsStringChanged)
Q_PROPERTY(bool error READ error NOTIFY errorChanged)
public:
enum {
......@@ -67,6 +68,8 @@ public:
QString icsString() const;
void setIcsString(const QString &icsData);
bool error() const;
virtual int rowCount(const QModelIndex &index) const;
virtual QVariant data(const QModelIndex &index, int role) const;
......@@ -77,6 +80,7 @@ signals:
void countChanged();
void fileNameChanged();
void icsStringChanged();
bool errorChanged();
public slots:
bool importToNotebook(const QString &notebookUid = QString());
......@@ -87,10 +91,12 @@ protected:
private:
void reload();
bool importToMemory(const QString &fileName, const QByteArray &icsData);
void setError(bool error);
QString mFileName;
QByteArray mIcsRawData;
KCalendarCore::Event::List mEventList;
bool mError;
};
#endif // CALENDARIMPORT_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment