#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMediaPlayer>
//#include <QtMultimedia/QMediaMetaData>
#include <QtWidgets>
#include <QWidget>
#include <QMessageBox>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
for(int i=0; i <10 ; i++)
{
Buttons[i] = new SortButton;
}
ButtonArray[0] = ui->Button1;
ButtonArray[1] = ui->Button2;
ButtonArray[2] = ui->Button3;
ButtonArray[3] = ui->Button4;
ButtonArray[4] = ui->Button5;
ButtonArray[5] = ui->Button6;
ButtonArray[6] = ui->Button7;
ButtonArray[7] = ui->Button8;
ButtonArray[8] = ui->Button9;
ButtonArray[9] = ui->Button10;
for(int i = 0; i < 10; i++)
{
connect(ButtonArray[i], SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(ButtonArray[i], i);
//ButtonArray[i]->setToolTip(QString::number(i));
}
connect(signalMapper, SIGNAL(mapped(int)),
this, SLOT(FileMoves(int)));
FolderList = new QFileSystemModel(this);
FolderList->setRootPath("");
FolderList
->setFilter
(QDir::NoDotAndDotDot |
QDir::AllDirs);
ui->FolderTreeView->setModel(FolderList);
ui->FolderTreeView->hideColumn(1);
ui->FolderTreeView->hideColumn(2);
ui->FolderTreeView->hideColumn(3);
FileList = new QFileSystemModel(this);
FileList->setRootPath("");
FileList
->setFilter
(QDir::NoDotAndDotDot |
QDir::Files);
FileList
->setNameFilters
(QStringList() <<
"*.mp3" <<
"*.wav");
FileList->setNameFilterDisables(false);
ui->FileTableView->setModel(FileList);
ui->FileTableView->setRootIndex(FileList->setRootPath("C:\\"));
ui->FileTableView->setColumnWidth(0,200);
ui->FileTableView->setColumnWidth(2,60);
//ui->FileTreeView->setModel(FileList2);
MediaPlayer = new QMediaPlayer(this);
/*QString Error2 = MediaPlayer->errorString();
QMessageBox msgBox3;
msgBox3.setText(Error2);
msgBox3.exec();*/
// connect(MediaPlayer, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
// connect(MediaPlayer, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
MediaPlayer->setVolume(100);
//SetButtons();
// ui->FolderTreeView->hide();
// ui->FileTableView->hide();
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(About()));
connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::About(){
AboutBox.setText("Holy shit balls");
AboutBox.exec();
}
void MainWindow
::on_FolderTreeView_clicked(const QModelIndex &index
) {
QString FolderPath
= FolderList
->fileInfo
(index
).
absoluteFilePath();
ui->FileTableView->setRootIndex(FileList->setRootPath(FolderPath));
}
void MainWindow
::on_FolderTreeView_activated(const QModelIndex &index
) {
QString FolderPath
= FolderList
->fileInfo
(index
).
absoluteFilePath();
ui->FileTableView->setRootIndex(FileList->setRootPath(FolderPath));
}
void MainWindow
::on_FileTableView_activated(const QModelIndex &index
) {
MediaPlayer->stop();
QString FilePath
= FileList
->fileInfo
(index
).
absoluteFilePath();
MediaPlayer
->setMedia
(QUrl::fromLocalFile(FilePath
));
MediaPlayer->play();
/*
QString Error = MediaPlayer->errorString();
QMessageBox msgBox;
msgBox.setText(Error);
msgBox.exec();
QMessageBox msgBox2;
QString Available = "false";
QString AudioA = "false";
QString Muted = "false";
if(MediaPlayer->isAvailable())
Available = "true";
if(MediaPlayer->isAudioAvailable())
AudioA = "true";
if(MediaPlayer->isAvailable())
Muted = "true";
msgBox2.setText(Available + AudioA + Muted);
msgBox2.exec();
*/
}
void MainWindow::SetButtons(void){
for(int i = 0; i < 10; i++)
{
if (Buttons[i]->Name == "" || Buttons[i]->Folder == "" )
{
ButtonArray[i]->setText("");
ButtonArray[i]->setEnabled(false);
} else {
TempText = Buttons[i]->Name + "\n" + "(&" +Buttons[i]->Hotkey.toString()+")";
ButtonArray[i]->setText(TempText);
ButtonArray[i]->setEnabled(true);
ButtonArray[i]->setShortcut(Buttons[i]->Hotkey);
}
}
//ButtonArray[9]->setEnabled(false);
}
void MainWindow
::LoadRootInfo(QString Root,
bool Copy
) {
SampleRoot = Root;
CopyMove = Copy;
ui->FolderTreeView->setCurrentIndex(TempI);
QString FolderPath
= FolderList
->fileInfo
(TempI
).
absoluteFilePath();
ui->FileTableView->setRootIndex(FileList->setRootPath(FolderPath));
}
void MainWindow::FileMoves(int Array)
{
MediaPlayer->stop();
TempIndex = ui->FileTableView->currentIndex();
QString FileName
= FileList
->fileInfo
(TempIndex
).
fileName();
if(FileName != "" && FileList->isDir(TempIndex) == false)
{
QString OriginalFile
= FileList
->fileInfo
(TempIndex
).
absoluteFilePath();
FinalFile.prepend(Buttons[Array]->Folder+"\\");
if(CopyMove == false)
{
File.copy(OriginalFile,FinalFile);
} else {
File.rename(OriginalFile,FinalFile);
}
}
//Play Next
TempIndex2 = ui->FileTableView->currentIndex();
ui->FileTableView->selectRow(TempIndex2.row() + 1);
ui->FileTableView->setFocus();
TempIndex3 = ui->FileTableView->currentIndex();
if(TempIndex2 != TempIndex3)
{
QString FilePath
= FileList
->fileInfo
(TempIndex3
).
absoluteFilePath();
MediaPlayer
->setMedia
(QUrl::fromLocalFile(FilePath
));
MediaPlayer->play();
}
}
void MainWindow::on_StopButton_clicked()
{
MediaPlayer->stop();
}
void MainWindow::on_PlayButton_clicked()
{
MediaPlayer->stop();
TempIndex = ui->FileTableView->currentIndex();
QString FilePath
= FileList
->fileInfo
(TempIndex
).
absoluteFilePath();
MediaPlayer
->setMedia
(QUrl::fromLocalFile(FilePath
));
MediaPlayer->play();
}
void MainWindow::on_NextButton_clicked()
{
MediaPlayer->stop();
TempIndex = ui->FileTableView->currentIndex();
ui->FileTableView->selectRow(TempIndex.row() + 1);
ui->FileTableView->setFocus();
TempIndex2 = ui->FileTableView->currentIndex();
if(TempIndex != TempIndex2)
{
QString FilePath
= FileList
->fileInfo
(TempIndex2
).
absoluteFilePath();
MediaPlayer
->setMedia
(QUrl::fromLocalFile(FilePath
));
MediaPlayer->play();
}
}
void MainWindow::on_PrevButton_clicked()
{
MediaPlayer->stop();
TempIndex = ui->FileTableView->currentIndex();
ui->FileTableView->selectRow(TempIndex.row() - 1);
ui->FileTableView->setFocus();
TempIndex2 = ui->FileTableView->currentIndex();
if(TempIndex != TempIndex2)
{
QString FilePath
= FileList
->fileInfo
(TempIndex2
).
absoluteFilePath();
MediaPlayer
->setMedia
(QUrl::fromLocalFile(FilePath
));
MediaPlayer->play();
}
}
void MainWindow::display()
{
showMaximized();
SetButtons();
}
{
Buttons[Array]->Folder = Fold;
Buttons[Array]->Hotkey = Hot;
Buttons[Array]->Name = Nam;
}
Bookmarks