Crossfire Server, Trunk
MimeUtils.h
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #ifndef MIME_UTILS_H
14 #define MIME_UTILS_H
15 
16 #include <QString>
17 #include <QList>
18 #include <QMimeData>
19 #include <QDataStream>
20 #include <QIODevice>
21 #include "AssetsCollection.h"
22 
23 namespace MimeUtils {
24  static const char *Archetype = "x-crossfire/archetype";
25  static const char *TreasureList = "x-crossfire/treasure-list";
26  static const char *QuestStep = "x-crossfire/quest-step";
27 
28  void addMime(QMimeData *data, const QString &mime, const QString &name);
29 
30  template<class T>
31  static QList<T *> extract(const QMimeData *data, const QString &mime, AssetsCollection<T> *assets) {
32  QList<T *> ret;
33  if (data->hasFormat(mime)) {
34  QByteArray ba(data->data(mime));
35  QDataStream df(&ba, QIODevice::ReadOnly);
36  QString name;
37  while (!df.atEnd()) {
38  df >> name;
39  if (!name.isEmpty()) {
40  auto asset = assets->find(name.toLocal8Bit().data());
41  if (asset) {
42  ret.push_back(asset);
43  }
44  }
45  }
46  }
47  return ret;
48  }
49 
50  void addQuestStep(QMimeData *data, QString code, int index);
51  QList<QPair<QString, int>> extractQuestSteps(const QMimeData *data);
52 }
53 
54 #endif /* MIME_UTILS_H */
MimeUtils::Archetype
static const char * Archetype
Definition: MimeUtils.h:24
MimeUtils::addMime
void addMime(QMimeData *data, const QString &mime, const QString &name)
Definition: MimeUtils.cpp:17
MimeUtils::extractQuestSteps
QList< QPair< QString, int > > extractQuestSteps(const QMimeData *data)
Definition: MimeUtils.cpp:31
MimeUtils::QuestStep
static const char * QuestStep
Definition: MimeUtils.h:26
MimeUtils
Definition: MimeUtils.cpp:15
AssetsCollection::find
T * find(const Key &name)
Definition: AssetsCollection.h:108
MimeUtils::TreasureList
static const char * TreasureList
Definition: MimeUtils.h:25
AssetsCollection
Definition: AssetsCollection.h:55
MimeUtils::addQuestStep
void addQuestStep(QMimeData *data, QString code, int index)
Definition: MimeUtils.cpp:24
AssetsCollection.h
navar-midane_time.data
data
Definition: navar-midane_time.py:11
MimeUtils::extract
static QList< T * > extract(const QMimeData *data, const QString &mime, AssetsCollection< T > *assets)
Definition: MimeUtils.h:31
npc_dialog.index
int index
Definition: npc_dialog.py:102
give.name
name
Definition: give.py:27