|
From: Tapio V. <aa...@us...> - 2011-02-22 18:24:52
|
Author: Tapio Vierros <tap...@gm...>
Date: Tue Feb 22 20:24:04 2011 +0200
Detect if user tries to load song file as plain text and ask for action.
---
editorapp.cc | 12 +++++++++++-
songparser.hh | 13 +++++++++----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/editorapp.cc b/editorapp.cc
index 82061d9..a185764 100644
--- a/editorapp.cc
+++ b/editorapp.cc
@@ -18,6 +18,7 @@
#include "editorapp.hh"
#include "notelabel.hh"
#include "notegraphwidget.hh"
+#include "songparser.hh"
#include "songwriter.hh"
#include "textcodecselector.hh"
#include "gettingstarted.hh"
@@ -633,7 +634,16 @@ void EditorApp::on_actionLyricsFromFile_triggered()
return;
QString text = TextCodecSelector::readAllAndHandleEncoding(file, this);
- if (text != "") noteGraph->setLyrics(text);
+ if (text != "") {
+ if (SongParser::looksLikeSongFile(text)
+ && QMessageBox::question(this, tr("Song file detected"),
+ tr("The file you are opening doesn't look like plain text lyrics, but rather an actual song file. Would you like to reload it as such?"),
+ QMessageBox::Yes | QMessageBox::No)
+ == QMessageBox::Yes)
+ {
+ openFile(fileName);
+ } else noteGraph->setLyrics(text);
+ }
}
}
}
diff --git a/songparser.hh b/songparser.hh
index f791923..2aa7cc0 100644
--- a/songparser.hh
+++ b/songparser.hh
@@ -13,6 +13,11 @@ class SongParser {
public:
/// constructor
SongParser(Song& s);
+
+ static bool looksLikeSongFile(QString const& data) {
+ return txtCheck(data) || xmlCheck(data) || iniCheck(data) || smCheck(data);
+ }
+
private:
void finalize();
@@ -24,22 +29,22 @@ class SongParser {
double m_gap;
// UltraStar TXT
- bool txtCheck(QString const& data);
+ static bool txtCheck(QString const& data);
void txtParse();
bool txtParseField(QString const& line);
bool txtParseNote(QString line, VocalTrack &vocal);
// SingStar XML
- bool xmlCheck(QString const& data);
+ static bool xmlCheck(QString const& data);
void xmlParse();
- bool iniCheck(QString const& data);
+ static bool iniCheck(QString const& data);
void iniParse();
void iniParseField(QString const& line);
void midParse();
// FIXME: Dummy funcs
- bool smCheck(QString const& data) { (void)data; return false; }
+ static bool smCheck(QString const& data) { (void)data; return false; }
void smParse() { }
bool smParseField(std::string line) { (void)line; return false; }
Notes smParseNotes(std::string line) { (void)line; return Notes(); }
|