Kyle_Katarn
5th April 2011, 18:02
Hi there, I guess this marks my first post here. I've been going at my own pace with Qt for a few weeks (and I have to say it's got to be my favorite Application development library of all time!)
Anyway, since I'm a big music person, I have a good lot of files with different naming conventions and such, so I thought it would be cool to apply my skills as a programmer and write a simple batch music file renamer as my first independent Qt app. I have made some surprising progress in the first day, I have been able to specify a folder, and populate a table with the files in that folder (even being able to filter out to specific filetypes!) I know it must sound boring to you guys, but as a programmer who's spent most of his time with more realtime application development (games and such), I think it's just magical.
I know my title states "Odd behavior," but in actual fact it's probably something so simple that I've overlooked and need a good bonk over the head for, but anyway, before I populate my table, all I have are three columns "File Name" (I'm still looking for a way to make this column non-editable), "Song Title" and "Song Number." The idea is that you're supposed load a folder (this is assuming you dont have all your mp3's in one folder, but rather separate them into separate folders by artist, album, whatever like myself), and then set some Global fields (artist name, album title, etc), then you can go into the local fields and set them yourself (or I could try to develop an algorithm to do it for you if I ever are smart to do that enough), then hit the rename button and its all done for you.
Before I load in a folder, my application looks like this:
http://img20.imageshack.us/img20/5923/brn01.png
And after I load in say Aerosmith's Ultimate Hits CD1:
http://img545.imageshack.us/img545/9287/brn02.png
As you can see, the Column names have been replaced by numbers. Now I think the solution to this is probably very simple (problems like these usually are), but I cant for the life of me think of what is going on...
Also the obligatory source code:
void BatchRenamer::populateTable( QString folderName )
{
// no need to validate folderName because it's already done in openFolder()
QDir activeDirectory( folderName );
QStringList fileList = activeDirectory.entryList( QStringList() << "*.mp3" << "*.wma", QDir::Files );
// clear the current file list before doing anything
ui.tblFiles->clear();
if ( !oldFileList.isEmpty() )
{
for ( int i = 0 ; i < oldFileList.size() ; i++ )
{
ui.tblFiles->removeRow(i);
ui.tblFiles->hideRow(i);
}
}
for ( int i = 0; i < fileList.size() ; i++ )
{
QTableWidgetItem* item = new QTableWidgetItem( fileList.at(i));
ui.tblFiles->insertRow(i);
ui.tblFiles->setItem(i, 0, item);
ui.tblFiles->showRow(i);
}
oldFileList = fileList;
}
And the method that calls populateTable(), which itself is called by a connection of the Find folder button clicked signal:
void BatchRenamer::openFolder()
{
QString folderName = QFileDialog::getExistingDirectory( this, "Select Media Folder" );
if( !folderName.isEmpty() )
{
ui.ledSelectedFolder->setText(folderName);
populateTable( folderName );
}
}
Thank you for your time. I would really appreciate instead of someone posting the code saying this works: go, take the time and explain to me why it's doing what it's doing and how I can go about fixing it. Of course, you dont have to though. :)
tl;dr:
When I populate my table, the column names get replaced with numbers.
Anyway, since I'm a big music person, I have a good lot of files with different naming conventions and such, so I thought it would be cool to apply my skills as a programmer and write a simple batch music file renamer as my first independent Qt app. I have made some surprising progress in the first day, I have been able to specify a folder, and populate a table with the files in that folder (even being able to filter out to specific filetypes!) I know it must sound boring to you guys, but as a programmer who's spent most of his time with more realtime application development (games and such), I think it's just magical.
I know my title states "Odd behavior," but in actual fact it's probably something so simple that I've overlooked and need a good bonk over the head for, but anyway, before I populate my table, all I have are three columns "File Name" (I'm still looking for a way to make this column non-editable), "Song Title" and "Song Number." The idea is that you're supposed load a folder (this is assuming you dont have all your mp3's in one folder, but rather separate them into separate folders by artist, album, whatever like myself), and then set some Global fields (artist name, album title, etc), then you can go into the local fields and set them yourself (or I could try to develop an algorithm to do it for you if I ever are smart to do that enough), then hit the rename button and its all done for you.
Before I load in a folder, my application looks like this:
http://img20.imageshack.us/img20/5923/brn01.png
And after I load in say Aerosmith's Ultimate Hits CD1:
http://img545.imageshack.us/img545/9287/brn02.png
As you can see, the Column names have been replaced by numbers. Now I think the solution to this is probably very simple (problems like these usually are), but I cant for the life of me think of what is going on...
Also the obligatory source code:
void BatchRenamer::populateTable( QString folderName )
{
// no need to validate folderName because it's already done in openFolder()
QDir activeDirectory( folderName );
QStringList fileList = activeDirectory.entryList( QStringList() << "*.mp3" << "*.wma", QDir::Files );
// clear the current file list before doing anything
ui.tblFiles->clear();
if ( !oldFileList.isEmpty() )
{
for ( int i = 0 ; i < oldFileList.size() ; i++ )
{
ui.tblFiles->removeRow(i);
ui.tblFiles->hideRow(i);
}
}
for ( int i = 0; i < fileList.size() ; i++ )
{
QTableWidgetItem* item = new QTableWidgetItem( fileList.at(i));
ui.tblFiles->insertRow(i);
ui.tblFiles->setItem(i, 0, item);
ui.tblFiles->showRow(i);
}
oldFileList = fileList;
}
And the method that calls populateTable(), which itself is called by a connection of the Find folder button clicked signal:
void BatchRenamer::openFolder()
{
QString folderName = QFileDialog::getExistingDirectory( this, "Select Media Folder" );
if( !folderName.isEmpty() )
{
ui.ledSelectedFolder->setText(folderName);
populateTable( folderName );
}
}
Thank you for your time. I would really appreciate instead of someone posting the code saying this works: go, take the time and explain to me why it's doing what it's doing and how I can go about fixing it. Of course, you dont have to though. :)
tl;dr:
When I populate my table, the column names get replaced with numbers.