Skip to content

Commit

Permalink
bug fix for rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomogroppi committed Dec 9, 2020
1 parent a4b7d81 commit 026888a
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 129 deletions.
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: writernote
version: 1.2.10
version: 1.2.11

summary: Writernote

Expand Down
8 changes: 5 additions & 3 deletions src/currenttitle/audiototext.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifndef AUDIO_TO_TEXT_CPP
#define AUDIO_TO_TEXT_CPP
#include "audiototext.h"
#include "../mainwindow.h"

#endif
void audiototext(MainWindow *padre, int posizione){

}
8 changes: 8 additions & 0 deletions src/currenttitle/audiototext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef AUDIOTOTEXT_H
#define AUDIOTOTEXT_H

#include "../mainwindow.h"

void audiototext(MainWindow *padre, int posizione);

#endif // AUDIOTOTEXT_H
5 changes: 0 additions & 5 deletions src/currenttitle/compressvideo.cpp

This file was deleted.

6 changes: 4 additions & 2 deletions src/currenttitle/deletecopybook.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef DELETE_COPY_BOOK_CPP
#define DELETE_COPY_BOOK_CPP

#include "deletecopybook.h"

#include "../mainwindow.h"
#include "ui_mainwindow.h"
#include "../areyousure.h"
Expand All @@ -10,10 +12,10 @@
#include "../update_list_copybook.h"

#include <QMediaPlayer>
#include "redolist.cpp"
#include "redolist.h"

/* funzione che gestisce l'eliminizione del copybook */
void f_deletecopybook( MainWindow *parent, const char *copybook = nullptr){
void f_deletecopybook( MainWindow *parent, const char *copybook){
if(!areyousure(parent, "Delete copybook", "are you sure you want to delete " + (QString)copybook + "?"))
return redolist(parent);

Expand Down
8 changes: 8 additions & 0 deletions src/currenttitle/deletecopybook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef DELETECOPYBOOK_H
#define DELETECOPYBOOK_H

#include "../mainwindow.h"

void f_deletecopybook( MainWindow *parent, const char *copybook = nullptr);

#endif // DELETECOPYBOOK_H
8 changes: 0 additions & 8 deletions src/currenttitle/main_include_currenttitle.h

This file was deleted.

5 changes: 1 addition & 4 deletions src/currenttitle/redolist.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef REDO_LIST_CPP
#define REDO_LIST_CPP
#include "redolist.h"

#include "../mainwindow.h"
#include "ui_mainwindow.h"
Expand All @@ -15,5 +14,3 @@ void redolist(MainWindow *parent)
int posizione = parent->self->indice.titolo.indexOf(parent->self->currentTitle, 0);
parent->ui->listWidgetSX->setCurrentRow(posizione);
}

#endif
27 changes: 21 additions & 6 deletions src/currenttitle/renamefile.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#ifndef CURRENT_TITLE_RENAME_FILE_CPP
#define CURRENT_TITLE_RENAME_FILE_CPP
#include "renamefile.h"

#include "../mainwindow.h"
#include "redolist.cpp"
#include "redolist.h"
#include "QInputDialog"
#include "../dialog_critic.h"
#include "../datawrite/renamefile_f_zip.h"
#include "../update_list_copybook.h"

#include "ui_mainwindow.h"

#include "../datawrite/savefile.h"

void renamefile(MainWindow *parent, const char *namefile){
bool checkname = (parent->ui->listWidgetSX->currentItem()->text() == parent->self->currentTitle);

bool ok;
QString namecopybook = QInputDialog::getText(parent, "Rename",
(QString)"Rename " + parent->ui->listWidgetSX->currentItem()->text(), QLineEdit::Normal,
"", &ok);
parent->ui->listWidgetSX->currentItem()->text(), &ok);
if(!ok || namecopybook == "")
return redolist(parent);

Expand All @@ -29,7 +34,17 @@ void renamefile(MainWindow *parent, const char *namefile){

parent->self->indice.titolo[posizione] = namecopybook;

savefile file_(parent, &parent->self->currentTitle);

if(!file_.savefile_check_indice()){
renamefile_f_zip(parent->self->path.c_str(), namecopybook.toUtf8().constData(), namefile);
dialog_critic("We had an error saving the index of the file");
return update_list_copybook(parent);
}

parent->setWindowTitle("Writernote - " + namecopybook);
if(checkname)
parent->self->currentTitle = namecopybook;

return update_list_copybook(parent);
}

#endif //CURRENT_TITLE_RENAME_FILE_CPP
8 changes: 8 additions & 0 deletions src/currenttitle/renamefile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef RENAMEFILE_H
#define RENAMEFILE_H

#include "../mainwindow.h"

void renamefile(MainWindow *parent, const char *namefile);

#endif // RENAMEFILE_H
67 changes: 25 additions & 42 deletions src/currenttitle/rightclicklistcopybook.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,57 @@
#ifndef RIGHT_CLICK_LIST_COPYBOOK_CPP
#define RIGHT_CLICK_LIST_COPYBOOK_CPP

#include "../mainwindow.h"
#include "ui_mainwindow.h"


#include <QMenu>
#include "../dialog_critic.h"
#include <QInputDialog>
#include "redolist.cpp"
#include "redolist.h"
#include <QString>

#include "deletecopybook.cpp"
#include <QContextMenuEvent>

#include "deletecopybook.h"
#include "audiototext.h"
#include "renamefile.h"

#include "../areyousure.h"

void MainWindow::deletecopybook_f(){
if(!this->ui->listWidgetSX->currentItem()->isSelected())
return redolist(this);

f_deletecopybook(this, this->ui->listWidgetSX->currentItem()->text().toUtf8().constData());
}

#include "compressvideo.cpp"
void MainWindow::compressvideo_f(){
if(!this->ui->listWidgetSX->currentItem()->isSelected())
return redolist(this);

if(this->ui->listWidgetSX->currentItem()->text() != this->self->currentTitle){
if(!areyousure(this, "Warning", "For compress video you need to change the current copybook\nDo you want to continue?"))
return;

this->on_listWidgetSX_itemDoubleClicked(this->ui->listWidgetSX->currentItem());
}

this->on_actioncompress_video_triggered();
}

#include "renamefile.cpp"
void MainWindow::renamefile_f(){
if(!this->ui->listWidgetSX->currentItem()->isSelected())
return redolist(this);

renamefile(this, this->ui->listWidgetSX->currentItem()->text().toUtf8().constData());

}

#include "audiototext.cpp"

void MainWindow::audiototext_f(){
messaggio_utente("This option is not implemented in the current version");
if(!this->ui->listWidgetSX->currentItem()->isSelected())
if(!this->ui->listWidgetSX->currentItem()->isSelected()){
messaggio_utente("This version of writernote is not yet capable of translating audio to text");
return redolist(this);
}
}

#include "deleteaudio.h"
Expand Down Expand Up @@ -90,37 +106,4 @@ void MainWindow::contextMenuEvent(QContextMenuEvent *event){
menu.addAction(renamecopybook_action);
menu.exec(event->globalPos());
}
/*
action = contextMenu.exec_(self.mapToGlobal(event.pos()))
currentItem = self.listwidget.currentItem()
if currentItem is None: return
if action == self.listwidget.addQuaderno:
self.newCopyBook()
elif action == self.listwidget.deleteQuaderno:
self.deleteCopyBookFunction(currentItem=currentItem)
elif action == self.listwidget.deleteAudio:
self.deleteAudio_Function(currentItem=currentItem)
elif action == self.listwidget.renameCopybook:
if not isinstance(currentItem, str): currentItem = currentItem.text()
return rename.Rename(parent=self, copybook=currentItem)
elif action == self.listwidget.comprimiVideo:
self.compressVideo(currentItem)
elif action == self.listwidget.convert_textAudio:
if self.on_clickMenuList() is True:
self.convertAudioToText()
else:
pass
*/

#endif
26 changes: 22 additions & 4 deletions src/datawrite/renamefile_f_zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,42 @@
#include "zip.h"
#include "iostream"

#include "../dialog_critic.h"

bool renamefile_f_zip(const char *namezip, const char *from, const char *dest){
int errorp;
int errorp = 0;
zip_t *filezip;

//filezip = zip_open(namezip, ZIP_SOURCE_WRITE, &errorp);
filezip = zip_open(namezip, ZIP_CREATE, &errorp);

if(filezip == nullptr)
{
QFile file(namezip);
if(file.open(QIODevice::ReadOnly))
{
dialog_critic("File is only in read mode");
return false;
}
else if(!file.exists()){
dialog_critic("File didn't exist");
return false;
}

zip_error_t ziperror;
zip_error_init_with_code(&ziperror, errorp);
throw std::runtime_error("Failed to open output file " + (std::string)from + ": " + zip_error_strerror(&ziperror));
}

/* ZIP_FL_ENC_UTF_8 */
int indice = zip_name_locate(filezip, ((QString)from + ".xml").toUtf8().constData(), ZIP_FL_ENC_STRICT);

if(indice == -1)
{
dialog_critic("The file didn't exist in the zip");
return false;
}

int indice = zip_name_locate(filezip, from, 0);
if(zip_file_rename(filezip, indice, dest, ZIP_FL_ENC_UTF_8) == -1){
if(zip_file_rename(filezip, indice, ((QString)dest + ".xml").toUtf8().constData(), 0) == -1){
zip_error_t ziperror;
zip_error_init_with_code(&ziperror, errorp);

Expand Down
3 changes: 1 addition & 2 deletions src/datawrite/savefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ bool savefile::compressfile(const char *namefile, const char *text){
namefile: nome file da salvare ("indice.xml", "file2.xml")
text: testo da scrivere
*/
int errorp;
int errorp = 0;

zip_t *filezip = zip_open(this->parent->self->path.c_str(), ZIP_CREATE , &errorp);


if (filezip == nullptr) {
zip_error_t ziperror;
zip_error_init_with_code(&ziperror, errorp);
Expand Down
3 changes: 0 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "indice_class.h"
#include "self_class.h"

/* gestione copybook */
#include "currenttitle/main_include_currenttitle.h"

/* gestione della lista */
#include "currenttitle/redolist.h"

Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public slots:
/* la funzione serve anche per eliminare l'audio del copybook */
void on_listWidgetSX_itemDoubleClicked(QListWidgetItem *item);

void on_actioncompress_video_triggered();

private slots:
/* registrazione dell'audio */
void setOutputLocation();
Expand Down Expand Up @@ -132,7 +134,6 @@ private slots:

void on_actionDelete_audio_triggered();

void on_actioncompress_video_triggered();

void on_volumeSlider_actionTriggered(int action);

Expand Down
35 changes: 0 additions & 35 deletions src/ui_final/ui_final.cpp

This file was deleted.

16 changes: 16 additions & 0 deletions src/update_list_copybook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "update_list_copybook.h"
#include "mainwindow.h"

#include "ui_mainwindow.h"

void update_list_copybook(MainWindow *parent){
int i;

/*pulisce la lista*/
parent->ui->listWidgetSX->clear();

int lunghezzalista = parent->self->indice.titolo.length();

for(i=0 ; i < lunghezzalista; i++)
parent->ui->listWidgetSX->addItem(parent->self->indice.titolo[i]);
}
Loading

0 comments on commit 026888a

Please sign in to comment.