Browse Source

Upload files to ''

master
DrewTechs 3 years ago
parent
commit
92f342fa2f
  1. 323
      copyItemDialog.cpp
  2. 62
      copyItemDialog.h
  3. 123
      copyItemDialog.ui
  4. 16
      main.cpp
  5. 1572
      mainwindow.cpp

323
copyItemDialog.cpp

@ -0,0 +1,323 @@
#include "copyItemDialog.h"
#include "ui_copyItemDialog.h"
CopyItemDialog::CopyItemDialog(bool moveItem, QStringList notebookColorList, QStringList notebookDirList, QStringList list, QString itemName, QString itemLocation, QWidget *parent) :
QDialog(parent),
ui(new Ui::CopyItemDialog)
{
setMoveItemState(moveItem);
setNotebookColorList(notebookColorList);
setNotebookDirList(notebookDirList);
setDirectories(list);
setFileName(itemName);
setFileLocation(itemLocation);
ui->setupUi(this);
init();
}
CopyItemDialog::~CopyItemDialog()
{
delete ui;
}
void CopyItemDialog::init()
{
ui->fileNameBox->setText(getFileName());
if(moveItemState == false)
{
// Copying Item:
ui->moveItemState_Label->setText("Copy Item:");
} else {
// Moving Item:
ui->moveItemState_Label->setText("Move Item:");
}
addItemsToDirectory();
}
void CopyItemDialog::addItemsToDirectory()
{
int idx = 0;
for(idx = 0; idx < getDirectories().size(); idx++)
{
if(!getDirectories().at(idx).startsWith(" "))
{
ui->directorySelection->addItem(SetNotebookIcon(notebookcolorlist.at(idx)), getDirectories().at(idx));
} else {
ui->directorySelection->addItem(SetSectionGroupIcon(notebookcolorlist.at(idx)), getDirectories().at(idx));
}
}
}
QIcon CopyItemDialog::SetNotebookIcon(QString notebookColor)
{
QIcon icon;
QString iconPath = "../NoteBinder/Icons";
if(!QDir(iconPath).exists())
{
return icon;
}
if(notebookColor == "Red") {
icon = QIcon(iconPath + "/NotebookIcon_Red.png");
} else if(notebookColor == "Blue") {
icon = QIcon(iconPath + "/NotebookIcon_Blue.png");
} else if(notebookColor == "Purple") {
icon = QIcon(iconPath + "/NotebookIcon_Purple.png");
} else if(notebookColor == "Orange") {
icon = QIcon(iconPath + "/NotebookIcon_Orange.png");
} else if(notebookColor == "Yellow") {
icon = QIcon(iconPath + "/NotebookIcon_Yellow.png");
} else if(notebookColor == "Green") {
icon = QIcon(iconPath + "/NotebookIcon_Green.png");
} else if(notebookColor == "Cyan") {
icon = QIcon(iconPath + "/NotebookIcon_Cyan.png");
} else if(notebookColor == "Tan") {
icon = QIcon(iconPath + "/NotebookIcon_Tan.png");
} else if(notebookColor == "Teal") {
icon = QIcon(iconPath + "/NotebookIcon_Teal.png");
} else if(notebookColor == "Red Chalk") {
icon = QIcon(iconPath + "/NotebookIcon_RedChalk.png");
} else if(notebookColor == "Blue Mist") {
icon = QIcon(iconPath + "/NotebookIcon_BlueMist.png");
} else if(notebookColor == "Purple Mist") {
icon = QIcon(iconPath + "/NotebookIcon_PurpleMist.png");
} else if(notebookColor == "Magenta") {
icon = QIcon(iconPath + "/NotebookIcon_Magenta.png");
} else if(notebookColor == "Lemon Lime") {
icon = QIcon(iconPath + "/NotebookIcon_LemonLime.png");
} else if(notebookColor == "Apple") {
icon = QIcon(iconPath + "/NotebookIcon_Apple.png");
} else if(notebookColor == "Silver") {
icon = QIcon(iconPath + "/NotebookIcon_Silver.png");
} else if(notebookColor == "Black") {
icon = QIcon(iconPath + "/NotebookIcon_Black.png");
} else {
// If it's either White/None or an invalid value, set to the white icon
icon = QIcon(iconPath + "/NotebookIcon_White.png");
}
return icon;
}
QIcon CopyItemDialog::SetSectionGroupIcon(QString sectionGroupColor)
{
QIcon icon;
QString iconPath = "../NoteBinder/Icons";
if(!QDir(iconPath).exists())
{
return icon;
}
if(sectionGroupColor == "Red") {
icon = QIcon(iconPath + "/SectionGroupIcon_Red.png");
} else if(sectionGroupColor == "Blue") {
icon = QIcon(iconPath + "/SectionGroupIcon_Blue.png");
} else if(sectionGroupColor == "Purple") {
icon = QIcon(iconPath + "/SectionGroupIcon_Purple.png");
} else if(sectionGroupColor == "Orange") {
icon = QIcon(iconPath + "/SectionGroupIcon_Orange.png");
} else if(sectionGroupColor == "Yellow") {
icon = QIcon(iconPath + "/SectionGroupIcon_Yellow.png");
} else if(sectionGroupColor == "Green") {
icon = QIcon(iconPath + "/SectionGroupIcon_Green.png");
} else if(sectionGroupColor == "Cyan") {
icon = QIcon(iconPath + "/SectionGroupIcon_Cyan.png");
} else if(sectionGroupColor == "Tan") {
icon = QIcon(iconPath + "/SectionGroupIcon_Tan.png");
} else if(sectionGroupColor == "Teal") {
icon = QIcon(iconPath + "/SectionGroupIcon_Teal.png");
} else if(sectionGroupColor == "Red Chalk") {
icon = QIcon(iconPath + "/SectionGroupIcon_RedChalk.png");
} else if(sectionGroupColor == "Blue Mist") {
icon = QIcon(iconPath + "/SectionGroupIcon_BlueMist.png");
} else if(sectionGroupColor == "Purple Mist") {
icon = QIcon(iconPath + "/SectionGroupIcon_PurpleMist.png");
} else if(sectionGroupColor == "Magenta") {
icon = QIcon(iconPath + "/SectionGroupIcon_Magenta.png");
} else if(sectionGroupColor == "Lemon Lime") {
icon = QIcon(iconPath + "/SectionGroupIcon_LemonLime.png");
} else if(sectionGroupColor == "Apple") {
icon = QIcon(iconPath + "/SectionGroupIcon_Apple.png");
} else if(sectionGroupColor == "Silver") {
icon = QIcon(iconPath + "/SectionGroupIcon_Silver.png");
} else if(sectionGroupColor == "Black") {
icon = QIcon(iconPath + "/SectionGroupIcon_Black.png");
} else {
// If it's either White/None or an invalid value, set to the white icon
icon = QIcon(iconPath + "/SectionGroupIcon_White.png");
}
return icon;
}
/* Getters */
bool CopyItemDialog::getMoveItemState() const
{
return moveItemState;
}
QStringList CopyItemDialog::getDirectories() const
{
return var_directoryList;
}
QStringList CopyItemDialog::getNotebookDirList() const
{
return notebookdirList;
}
QStringList CopyItemDialog::getNotebookColorList() const
{
return notebookcolorlist;
}
QString CopyItemDialog::getFileName() const
{
return var_itemName;
}
QString CopyItemDialog::getFileLocation() const
{
return var_itemLocation;
}
/* Setters */
void CopyItemDialog::setMoveItemState(bool updateMoveState)
{
moveItemState = updateMoveState;
}
void CopyItemDialog::setDirectories(QStringList dirList)
{
var_directoryList = dirList;
}
void CopyItemDialog::setNotebookDirList(QStringList nbDirList)
{
notebookdirList = nbDirList;
}
void CopyItemDialog::setNotebookColorList(QStringList nbColorList)
{
notebookcolorlist = nbColorList;
}
void CopyItemDialog::setFileName(QString newItemName)
{
var_itemName = newItemName;
}
void CopyItemDialog::setFileLocation(QString newItemLocation)
{
var_itemLocation = newItemLocation;
}
void CopyItemDialog::on_buttonBox_accepted()
{
if(ui->fileNameBox->text() != "")
{
QString fullFileName = getFileLocation();
setFileName(ui->fileNameBox->text());
QString newFullFileName = getNotebookDirList().at(ui->directorySelection->currentIndex()) + QDir::separator() + getFileName();
QFile file(newFullFileName);
QDir dir(fullFileName);
QFileInfo fileInfo(newFullFileName);
if(fileInfo.absoluteFilePath() == fullFileName)
{
reject(); // Cannot write onto itself.
} else {
if(!file.exists())
{
if(fileInfo.isFile())
{
// File
file.copy(fullFileName, newFullFileName);
} else {
copyRecursively(fullFileName, newFullFileName);
QFile fileSectGr(newFullFileName + QDir::separator() + "sectiongroup.sectgr");
QStringList fileItems;
// Read This file
if(fileSectGr.exists())
{
if(fileSectGr.open(QIODevice::ReadOnly))
{
QTextStream in(&fileSectGr);
while(!in.atEnd())
{
fileItems += in.readLine();
}
}
fileSectGr.remove();
if (fileSectGr.open(QIODevice::ReadWrite)) {
QTextStream in(&fileSectGr);
in << fileInfo.fileName() << "\n" << fileItems.at(1) << "\n";
}
fileSectGr.close();
}
}
setFileLocation(newFullFileName);
accept();
} else {
QMessageBox messageBox;
QFont fontSize;
fontSize.setPointSize(12);
messageBox.setWindowTitle("Replace Existing Item?");
messageBox.setFont(fontSize);
messageBox.setText("Item already exists! Do you want to overwrite it?");
messageBox.setStandardButtons(QMessageBox::Yes);
messageBox.addButton(QMessageBox::No);
messageBox.setDefaultButton(QMessageBox::No);
if(messageBox.exec() == QMessageBox::Yes)
{
if(fileInfo.isFile())
{
// File
file.copy(fullFileName, newFullFileName);
} else {
copyRecursively(fullFileName, newFullFileName);
QFile fileSectGr(newFullFileName + QDir::separator() + "sectiongroup.sectgr");
QStringList fileItems;
// Read This file
if(fileSectGr.exists())
{
if(fileSectGr.open(QIODevice::ReadOnly))
{
QTextStream in(&fileSectGr);
while(!in.atEnd())
{
fileItems += in.readLine();
}
}
fileSectGr.remove();
if (fileSectGr.open(QIODevice::ReadWrite)) {
QTextStream in(&fileSectGr);
in << fileInfo.fileName() << "\n" << fileItems.at(1) << "\n";
}
fileSectGr.close();
}
}
setFileLocation(newFullFileName);
accept();
} else {
reject();
}
}
}
}
}
void CopyItemDialog::on_buttonBox_rejected()
{
reject();
}
bool CopyItemDialog::copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
{
/* Function written by ssendeavour: https://gist.github.com/ssendeavour/7324701#file-copy-recursively-cpp */
QFileInfo srcFileInfo(srcFilePath);
if (srcFileInfo.isDir())
{
QDir targetDir(tgtFilePath);
targetDir.cdUp();
if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
return false;
QDir sourceDir(srcFilePath);
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
foreach (const QString &fileName, fileNames)
{
const QString newSrcFilePath = srcFilePath + QDir::separator() + fileName;
const QString newTgtFilePath = tgtFilePath + QDir::separator() + fileName;
if (!copyRecursively(newSrcFilePath, newTgtFilePath))
return false;
}
} else {
if (!QFile::copy(srcFilePath, tgtFilePath))
return false;
}
return true;
}

62
copyItemDialog.h

@ -0,0 +1,62 @@
#ifndef COPYITEMDIALOG_H
#define COPYITEMDIALOG_H
#include <QDialog>
#include <QDir>
#include <QFileInfo>
#include "notebook.h"
#include "sectiongroup.h"
#include "notebooklist.h"
#include "notebookmanager.h"
namespace Ui {
class CopyItemDialog;
}
class CopyItemDialog : public QDialog
{
Q_OBJECT
public:
explicit CopyItemDialog(bool moveItem, QStringList notebookColorList, QStringList notebookDirList, QStringList list, QString itemName, QString itemLocation, QWidget *parent = nullptr);
~CopyItemDialog();
void init();
void addItemsToDirectory();
/* Function written by ssendeavour: https://gist.github.com/ssendeavour/7324701#file-copy-recursively-cpp */
static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath);
QIcon SetNotebookIcon(QString notebookColor);
QIcon SetSectionGroupIcon(QString sectionGroupColor);
/* Getters */
bool getMoveItemState() const;
QStringList getDirectories() const;
QStringList getNotebookDirList() const;
QStringList getNotebookColorList() const;
QString getFileName() const;
QString getFileLocation() const;
/* Setters */
void setMoveItemState(bool updateMoveState);
void setDirectories(QStringList dirList);
void setNotebookDirList(QStringList nbDirList);
void setNotebookColorList(QStringList nbColorList);
void setFileName(QString newItemName);
void setFileLocation(QString newItemLocation);
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::CopyItemDialog *ui;
bool moveItemState;
QString var_itemName;
QString var_itemLocation;
QStringList notebookdirList; // Actual Filepaths of each Notebook or Section Group.
QStringList var_directoryList; // Directories displayed on the ComboBox of Directory List
QStringList notebookcolorlist; // Icon Colors of Notebook or Section Group
};
#endif // COPYITEMDIALOG_H

123
copyItemDialog.ui

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CopyItemDialog</class>
<widget class="QDialog" name="CopyItemDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<height>221</height>
</rect>
</property>
<property name="windowTitle">
<string>Copy/Move Item</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="moveItemState_Label">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Copy/Move Item:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="fileNameBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="notebookLabel">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Select Notebook or Section Group:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="directorySelection">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CopyItemDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CopyItemDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

16
main.cpp

@ -0,0 +1,16 @@
/* DrewTechs
* Note Binder
* @Version 1.0
*/
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

1572
mainwindow.cpp

File diff suppressed because it is too large
Loading…
Cancel
Save