mirror of
https://github.com/UltimMC/Launcher.git
synced 2025-10-04 17:09:25 +00:00
Compare commits
3 Commits
0.6.10
...
feature/mo
Author | SHA1 | Date | |
---|---|---|---|
|
f04502cd82 | ||
|
4233e0c014 | ||
|
cec5f7332e |
@@ -21,6 +21,7 @@
|
||||
#include <QString>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QDebug>
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
SimpleModList::SimpleModList(const QString &dir) : QAbstractListModel(), m_dir(dir)
|
||||
{
|
||||
@@ -97,7 +98,7 @@ bool SimpleModList::isValid()
|
||||
}
|
||||
|
||||
// FIXME: this does not take disabled mod (with extra .disable extension) into account...
|
||||
bool SimpleModList::installMod(const QString &filename)
|
||||
bool SimpleModList::installMod(const QString &filename, bool move)
|
||||
{
|
||||
// NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName
|
||||
auto originalPath = FS::NormalizePath(filename);
|
||||
@@ -143,7 +144,7 @@ bool SimpleModList::installMod(const QString &filename)
|
||||
}
|
||||
qDebug() << newpath << "has been deleted.";
|
||||
}
|
||||
if (!QFile::copy(fileinfo.filePath(), newpath))
|
||||
if (move ? !QFile::rename(fileinfo.filePath(), newpath) : !QFile::copy(fileinfo.filePath(), newpath))
|
||||
{
|
||||
qWarning() << "Copy from" << originalPath << "to" << newpath << "has failed.";
|
||||
// FIXME: report error in a user-visible way
|
||||
@@ -163,7 +164,7 @@ bool SimpleModList::installMod(const QString &filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!FS::copy(from, newpath)())
|
||||
if (move ? !QDir().rename(from, newpath) : !FS::copy(from, newpath)())
|
||||
{
|
||||
qWarning() << "Copy of folder from" << originalPath << "to" << newpath << "has (potentially partially) failed.";
|
||||
return false;
|
||||
@@ -307,15 +308,13 @@ QVariant SimpleModList::headerData(int section, Qt::Orientation orientation, int
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags SimpleModList::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
|
||||
if (index.isValid())
|
||||
return Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled |
|
||||
defaultFlags;
|
||||
return Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | defaultFlags;
|
||||
else
|
||||
return Qt::ItemIsDropEnabled | defaultFlags;
|
||||
}
|
||||
@@ -326,6 +325,11 @@ Qt::DropActions SimpleModList::supportedDropActions() const
|
||||
return Qt::CopyAction | Qt::MoveAction;
|
||||
}
|
||||
|
||||
Qt::DropActions SimpleModList::supportedDragActions() const
|
||||
{
|
||||
return Qt::CopyAction | Qt::MoveAction;
|
||||
}
|
||||
|
||||
QStringList SimpleModList::mimeTypes() const
|
||||
{
|
||||
QStringList types;
|
||||
@@ -333,6 +337,7 @@ QStringList SimpleModList::mimeTypes() const
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
bool SimpleModList::dropMimeData(const QMimeData* data, Qt::DropAction action, int, int, const QModelIndex&)
|
||||
{
|
||||
if (action == Qt::IgnoreAction)
|
||||
@@ -357,11 +362,29 @@ bool SimpleModList::dropMimeData(const QMimeData* data, Qt::DropAction action, i
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// TODO: implement not only copy, but also move
|
||||
// FIXME: handle errors here
|
||||
installMod(url.toLocalFile());
|
||||
installMod(url.toLocalFile(), action == Qt::DropAction::MoveAction);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QMimeData *SimpleModList::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
auto *mimeData = new QMimeData();
|
||||
QByteArray encodedData;
|
||||
|
||||
QDataStream stream(&encodedData, QIODevice::WriteOnly);
|
||||
for(const auto &index : indexes)
|
||||
{
|
||||
if(index.isValid())
|
||||
{
|
||||
auto mod = mods[index.row()];
|
||||
stream << "file://" << mod.filename().absoluteFilePath() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
mimeData->setData("text/uri-list", encodedData);
|
||||
return mimeData;
|
||||
}
|
@@ -49,11 +49,13 @@ public:
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
|
||||
/// flags, mostly to support drag&drop
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
QStringList mimeTypes() const override;
|
||||
bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) override;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
|
||||
virtual int rowCount(const QModelIndex &) const override
|
||||
{
|
||||
@@ -83,7 +85,7 @@ public:
|
||||
/**
|
||||
* Adds the given mod to the list at the given index - if the list supports custom ordering
|
||||
*/
|
||||
bool installMod(const QString& filename);
|
||||
bool installMod(const QString& filename, bool move);
|
||||
|
||||
/// Deletes all the selected mods
|
||||
virtual bool deleteMods(const QModelIndexList &indexes);
|
||||
|
@@ -33,7 +33,7 @@ slots:
|
||||
QString folder = source;
|
||||
QTemporaryDir tempDir;
|
||||
SimpleModList m(tempDir.path());
|
||||
m.installMod(folder);
|
||||
m.installMod(folder, false);
|
||||
verify(tempDir.path());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ slots:
|
||||
QString folder = source + '/';
|
||||
QTemporaryDir tempDir;
|
||||
SimpleModList m(tempDir.path());
|
||||
m.installMod(folder);
|
||||
m.installMod(folder, false);
|
||||
verify(tempDir.path());
|
||||
}
|
||||
}
|
||||
|
@@ -163,7 +163,7 @@ void ModFolderPage::on_addModBtn_clicked()
|
||||
{
|
||||
for (auto filename : list)
|
||||
{
|
||||
m_mods->installMod(filename);
|
||||
m_mods->installMod(filename, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -35,8 +35,10 @@ ModListView::ModListView ( QWidget* parent )
|
||||
setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
|
||||
setDropIndicatorShown(true);
|
||||
setDragEnabled(true);
|
||||
setDragDropMode(QAbstractItemView::DropOnly);
|
||||
setDragDropMode(QAbstractItemView::DragDrop);
|
||||
viewport()->setAcceptDrops(true);
|
||||
setAcceptDrops(true);
|
||||
setDefaultDropAction(Qt::CopyAction);
|
||||
}
|
||||
|
||||
void ModListView::setModel ( QAbstractItemModel* model )
|
||||
@@ -64,3 +66,18 @@ void ModListView::setModel ( QAbstractItemModel* model )
|
||||
head->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||
}
|
||||
}
|
||||
|
||||
void ModListView::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ModListView::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ModListView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QAbstractItemView::dropEvent(event);
|
||||
}
|
||||
|
@@ -22,6 +22,10 @@ class ModListView: public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ModListView ( QWidget* parent = 0 );
|
||||
virtual void setModel ( QAbstractItemModel* model );
|
||||
explicit ModListView ( QWidget* parent = nullptr );
|
||||
void setModel ( QAbstractItemModel* model ) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user