5 #include <QRegularExpression>
11 #include <QMessageBox>
12 #include <JlCompress.h>
16 :
QFrame(parent), mExistingDir(existingDir), mValid(false)
35 handleTextChanged(defaultEntry);
38 void FileSelectWidget::handleActivateFileDialog()
42 :
QFileDialog::getOpenFileName(this,
"Select file:", mEditor->text(),
"Zipped files (*.zip)");
46 void FileSelectWidget::handleTextChanged(
const QString &txt)
50 if (val == mValid)
return;
64 :
QDialog(parent), mStatus(NoImport)
83 mExtractProjectEdit =
new QLineEdit(
this);
92 handleSelectionStatusChanged();
98 handleSelectionStatusChanged();
102 void ImportProjectDialog::handleSelectionStatusChanged()
104 bool valid = mTargetDirectory->
valid() && mZippedFile->
valid();
109 int inx = zipFlist.
indexOf(reProj);
118 mTargetProjectName = match.
captured(1);
132 if (
QFileInfo(mExtractedProjectAbsolutePath).exists())
134 QMessageBox::warning(
this,
"Cannot Create Project",
"Direcotry " + mExtractedProjectAbsolutePath +
" already exists");
139 if (mExtractProjectEdit->
text() != mTargetProjectName)
143 extracted = JlCompress::extractDir(mZippedFile->
selection(),tempdir);
147 extracted = JlCompress::extractDir(mZippedFile->
selection(),mTargetDirectory->
selection());
150 if (extracted.
isEmpty())
return false;
154 extractedDir.
chop(1);
197 if (!
QFile::rename(extractedDir,mExtractedProjectAbsolutePath))
199 log_warning(
"gui",
"Failed to move decompressed archive to new location '{}'.", mExtractedProjectAbsolutePath.
toStdString());
205 deleteFilesRecursion(tempdir);
212 deleteFilesList(extracted);
219 void ImportProjectDialog::deleteFilesRecursion(
QString dir)
224 deleteFilesRecursion(finfo.absoluteFilePath());
231 void ImportProjectDialog::deleteFilesList(
QStringList files)
234 auto it = files.
begin();
235 while (it != files.
end())
241 it = files.
erase(it);
251 if (it == files.
begin())
static DirectoryStatus directoryStatus(const QString &pathname)
static QString suggestedProjectDir(const QString &filename)
ImportProjectDialog(QWidget *parent=nullptr)
void setZippedFile(const QString &filename)
#define log_warning(channel,...)
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
ushort unicode() const const
QString absoluteFilePath(const QString &fileName) const const
bool mkpath(const QString &dirPath) const const
bool rmdir(const QString &dirName) const const
bool rename(const QString &newName)
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options)
bool exists() const const
void setFrameStyle(int style)
void setText(const QString &)
void textChanged(const QString &text)
const T & at(int i) const const
QList::iterator erase(QList::iterator pos)
bool isEmpty() const const
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString captured(int nth) const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
QString & remove(int position, int n)
std::string toStdString() const const
int indexOf(QStringView str, int from) const const