[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-multimedia
Subject:    [noatun-patch] Renaming files from the id3tag plugin
From:       Ismael Orenstein <perdig () linuxbr ! com ! br>
Date:       2001-09-01 20:49:20
[Download RAW message or body]

Hey there!

One of the biggest problems I had with mp3 files was the fact that the 
filenames templates were very different. (for example, I can have a 
"radiohead - fake plastic tree.mp3", a "[Radiohead] - Fake plastic Tree.mp3", 
a "Fake plastic tree.mp3", etc). Besides, sometimes the filenames just don't 
match the music... so, I did a bit edting to the id3tag noatun plugin and 
added a "Rename" button. Clicking on it will popup a KFileDialog asking for a 
new name for your current music. It will suggest a name based on your id3tag 
configuration (defaults to "[%a] - %t") and then it will rename your file.

This patch also "fix" (I'm not sure if it was a bug) the behaviour of the 
plugin. If your id3tag editor is opened and you switch the current music, it 
will still display the last music. With my patch, it will load the current 
music. (in short: you can open the editor window, edit your current mp3, 
click on the "Forward" icon, edit the next mp3, click on the icon, etc)

Current issues with the patch:
- If you rename the file, your playlist will be outdated... there must be a 
way of updating the playlist to use the new filename
- When you switch your music, the editor is deleted and then created again, 
creating a little flick (it is closed, and then showed again). A better 
solution would be to just update the information on the window.

Well, that's it... I'm not sure if this diff file is in the correct format (I 
just did a "cvs diff > id3tag.diff" - using KDE_2_2_BRANCH code). If you want 
it to be different, just tell me.

Please feel free to use this patch as you want (it should be in the artistic 
license, just as the original code)

ps: Please forward any replies to perdig@linuxbr.com.br, as I'm not 
subscribed to this list

Best regards,

-- 
Ismael Orenstein (UIN 1293061)
perdig@linuxbr.com.br
http://ksnes9x.sourceforge.net
http://ggz.sourceforge.net
http://linuxgames.com/xrally
["id3tag.diff" (text/x-diff)]

Index: editor.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/noatun/modules/id3tag/editor.cpp,v
retrieving revision 1.13
diff -u -3 -p -r1.13 editor.cpp
--- editor.cpp	2001/07/01 18:56:48	1.13
+++ editor.cpp	2001/09/01 19:31:48
@@ -2,6 +2,9 @@
 #include <editor.h>
 #include <qlayout.h>
 #include <klineedit.h>
+#include <kio/job.h>
+#include <kfiledialog.h>
+#include <kdebug.h>
 #include <qlabel.h>
 #include <id3tag.h>
 #include <qfile.h>
@@ -55,35 +58,39 @@ Editor::Editor(NID3 *i)
 	connect(buttons, SIGNAL(clicked()), SLOT(save()));
 	buttons->setDefault(true);
 	grid->addWidget(buttons, 7, 2);
-
 	mSaveButton=buttons;
+
+  buttons = new QPushButton(i18n("Rename"), this);
+  connect(buttons, SIGNAL(clicked()), SLOT(rename()));
+  grid->addWidget(buttons, 7, 3);
+  mRenameButton = buttons;
 	
 	mName = new KLineEdit(this);
-	grid->addMultiCellWidget(mName, 1, 1, 1, 2);
+	grid->addMultiCellWidget(mName, 1, 1, 1, 3);
 	mName->setMaxLength(30);
 	connect(mName, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const \
QString&)));  
 	mArtist = new KLineEdit(this);
-	grid->addMultiCellWidget(mArtist, 2, 2, 1, 2);
+	grid->addMultiCellWidget(mArtist, 2, 2, 1, 3);
 	mArtist->setMaxLength(30);
 	connect(mArtist, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const \
QString&)));  
 	mAlbum = new KLineEdit(this);
-	grid->addMultiCellWidget(mAlbum, 3, 3, 1, 2);
+	grid->addMultiCellWidget(mAlbum, 3, 3, 1, 3);
 	mAlbum->setMaxLength(30);
 	connect(mAlbum, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const \
QString&)));  
 	mYear = new KLineEdit(this);
-	grid->addMultiCellWidget(mYear, 4, 4, 1, 2);
+	grid->addMultiCellWidget(mYear, 4, 4, 1, 3);
 	mYear->setMaxLength(4);
 	connect(mYear, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const \
QString&)));  
 	mGenre = new QComboBox(this);
-	grid->addMultiCellWidget(mGenre, 5, 5, 1, 2);
+	grid->addMultiCellWidget(mGenre, 5, 5, 1, 3);
 	connect(mGenre, SIGNAL(activated(const QString&)), SLOT(textChanged(const \
QString&)));  
 	mComment = new KLineEdit(this);
-	grid->addMultiCellWidget(mComment, 6, 6, 1, 2);
+	grid->addMultiCellWidget(mComment, 6, 6, 1, 3);
 	mComment->setMaxLength(30);
 	connect(mComment, SIGNAL(textChanged(const QString&)), SLOT(textChanged(const \
QString&)));  
@@ -169,6 +176,15 @@ void Editor::open(const QString &filen)
 	mYear->setText(parse(data.year,4));
 	mGenre->setCurrentItem((int)(data.genre));
 	mSaveButton->setEnabled(false);
+}
+
+void Editor::rename()
+{
+  KURL new_name(mFile->text());
+  new_name.setFileName(mID3Loader->getTitle(this).replace(QRegExp("/"), \
"%2f")+".mp3"); +  kdDebug() << "New file name:" << new_name.prettyURL() << endl;
+  if (!(new_name = KFileDialog::getSaveFileName(new_name.url(), "*.mp3")).isEmpty())
+    KIO::Job *job = KIO::move(KURL::KURL(mFile->text()), new_name, true);
 }
 
 void Editor::save()
Index: editor.h
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/noatun/modules/id3tag/editor.h,v
retrieving revision 1.6
diff -u -3 -p -r1.6 editor.h
--- editor.h	2001/06/18 19:56:25	1.6
+++ editor.h	2001/09/01 19:31:48
@@ -30,6 +30,7 @@ public slots:
 
 protected slots:
 	void save();
+  void rename();
 	void textChanged(const QString&dummy);
 
 protected:
@@ -41,6 +42,7 @@ private:
 	QLabel *mFile;
 	NID3 *mID3Loader;
 	QPushButton *mSaveButton;
+  QPushButton *mRenameButton;
 };
 
 #endif
Index: id3tag.cpp
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/noatun/modules/id3tag/id3tag.cpp,v
retrieving revision 1.25
diff -u -3 -p -r1.25 id3tag.cpp
--- id3tag.cpp	2001/06/04 02:19:51	1.25
+++ id3tag.cpp	2001/09/01 19:31:48
@@ -50,41 +50,49 @@ void NID3::editID3()
 static QString parseFormat(const QString &format, const QString &name, const QString \
                &artist, const QString &album,
                            const QString &comment, const QString &year, const \
QString &genre);  
+QString NID3::getTitle(const Editor *mEditor) const {
+	KConfig *config = KGlobal::config();
+	KConfigGroupSaver saver(config, "ID3 Tags");
+	QString format=config->readEntry("ID3Format", "%t");
+
+	QString title = parseFormat(format,mEditor->name(), mEditor->artist(),
+	                            mEditor->album(), mEditor->comment(), mEditor->year(), \
mEditor->genre()); +	// some titles/authors/songs might contain a / which is encoded \
as %2f +	// so replace the encoding with the /
+	title.replace( QRegExp("%2f"), "/" );
+
+  return title;
+}
+
 void NID3::newSong()
 {
+  bool visible = false;
 	PlaylistItem *item=napp->player()->current();
 	if (!item) return;
 	
-	if (mEditor && !mEditor->isVisible())
+	if (mEditor)
 	{
+    visible = mEditor->isVisible();
 		delete mEditor;
 		mEditor=0;
 	}
 
-	{
-		mEditor=new Editor(this);
-		mEditor->open(item->file());
-		connect(mEditor, SIGNAL(saved()), SLOT(newSong()));
-	}
+  mEditor=new Editor(this);
+  mEditor->open(item->file());
+  if (visible)
+    mEditor->show();
+  connect(mEditor, SIGNAL(saved()), SLOT(newSong()));
 
 	if (!mEditor->name().stripWhiteSpace().length()) return;
-
-	KConfig *config = KGlobal::config();
-	KConfigGroupSaver saver(config, "ID3 Tags");
-	QString format=config->readEntry("ID3Format", "%t");
 
-	QString title = parseFormat(format,mEditor->name(), mEditor->artist(),
-	                            mEditor->album(), mEditor->comment(), mEditor->year(), \
                mEditor->genre());
-	// some titles/authors/songs might contain a / which is encoded as %2f
-	// so replace the encoding with the /
-	title.replace( QRegExp("%2f"), "/" );
-	item->setTitle( title );
+	item->setTitle( getTitle(mEditor) );
 	
 //	item->setProperty("title", mEditor->name());
 	item->setProperty("artist", mEditor->artist());
 	item->setProperty("album", mEditor->album());
 	item->setProperty("date", mEditor->year());
 	item->setProperty("comment", mEditor->comment());
+
 }
 
 static QString parseFormat(const QString &format, const QString &name, const QString \
                &artist, const QString &album,
Index: id3tag.h
===================================================================
RCS file: /home/kde/kdemultimedia/noatun/noatun/modules/id3tag/id3tag.h,v
retrieving revision 1.11
diff -u -3 -p -r1.11 id3tag.h
--- id3tag.h	2001/03/10 01:23:13	1.11
+++ id3tag.h	2001/09/01 19:31:48
@@ -39,6 +39,7 @@ public:
 	virtual ~NID3();
 
 	Editor *editor() const {return mEditor;}
+  QString getTitle (const Editor *) const;
 public slots:
 	void newSong();
 	void editID3();


_______________________________________________
Kde-multimedia mailing list
Kde-multimedia@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-multimedia


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic