summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-10-20 12:32:47 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2013-10-20 12:32:47 +0200
commitbd8b9ef3aee80f37616a3ba0b4f61b8eb7fb6718 (patch)
treee0c109c83baaaa704141820ae38ee4788eadb029
parentce52d7285213ee359c92ec759e26d3b8d2f7fb11 (diff)
QPhotoRec: automatically select the image disk after addiing it
-rw-r--r--src/fnctdsk.c55
-rw-r--r--src/fnctdsk.h1
-rw-r--r--src/qphotorec.cpp34
3 files changed, 59 insertions, 31 deletions
diff --git a/src/fnctdsk.c b/src/fnctdsk.c
index abe012c..e50091d 100644
--- a/src/fnctdsk.c
+++ b/src/fnctdsk.c
@@ -102,37 +102,42 @@ void dup_partition_t(partition_t *dst, const partition_t *src)
#endif
}
-list_disk_t *insert_new_disk(list_disk_t *list_disk, disk_t *disk_car)
+list_disk_t *insert_new_disk_aux(list_disk_t *list_disk, disk_t *disk, disk_t **the_disk)
{
- if(disk_car==NULL)
+ list_disk_t *tmp;
+ list_disk_t *prev=NULL;
+ list_disk_t *new_disk;
+ if(disk==NULL)
return list_disk;
+ /* Add it at the end if it doesn't already exist */
+ for(tmp=list_disk;tmp!=NULL;tmp=tmp->next)
{
- list_disk_t *cur;
- list_disk_t *prev=NULL;
- list_disk_t *new_disk;
- /* Add it at the end if it doesn't already exist */
- for(cur=list_disk;cur!=NULL;cur=cur->next)
+ if(tmp->disk->device!=NULL && disk->device!=NULL &&
+ strcmp(tmp->disk->device, disk->device)==0)
{
- if(cur->disk->device!=NULL && disk_car->device!=NULL)
- {
- if(strcmp(cur->disk->device,disk_car->device)==0)
- {
- disk_car->clean(disk_car);
- return list_disk;
- }
- }
- prev=cur;
- }
- new_disk=(list_disk_t *)MALLOC(sizeof(*new_disk));
- new_disk->disk=disk_car;
- if(prev!=NULL)
- {
- prev->next=new_disk;
+ disk->clean(disk);
+ if(the_disk!=NULL)
+ *the_disk=tmp->disk;
+ return list_disk;
}
- new_disk->prev=prev;
- new_disk->next=NULL;
- return (list_disk!=NULL?list_disk:new_disk);
+ prev=tmp;
}
+ new_disk=(list_disk_t *)MALLOC(sizeof(*new_disk));
+ new_disk->disk=disk;
+ if(prev!=NULL)
+ {
+ prev->next=new_disk;
+ }
+ new_disk->prev=prev;
+ new_disk->next=NULL;
+ if(the_disk!=NULL)
+ *the_disk=disk;
+ return (list_disk!=NULL?list_disk:new_disk);
+}
+
+list_disk_t *insert_new_disk(list_disk_t *list_disk, disk_t *disk)
+{
+ return insert_new_disk_aux(list_disk, disk, NULL);
}
list_part_t *insert_new_partition(list_part_t *list_part, partition_t *part, const int force_insert, int *insert_error)
diff --git a/src/fnctdsk.h b/src/fnctdsk.h
index 79cedb4..6bdc760 100644
--- a/src/fnctdsk.h
+++ b/src/fnctdsk.h
@@ -30,6 +30,7 @@ unsigned int offset2head(const disk_t *disk_car, const uint64_t offset);
unsigned int offset2cylinder(const disk_t *disk_car, const uint64_t offset);
void offset2CHS(const disk_t *disk_car,const uint64_t offset, CHS_t*CHS);
+list_disk_t *insert_new_disk_aux(list_disk_t *list_disk, disk_t *disk, disk_t **the_disk);
list_disk_t *insert_new_disk(list_disk_t *list_disk, disk_t *disk_car);
list_part_t *insert_new_partition(list_part_t *list_part, partition_t *part, const int force_insert, int *insert_error);
list_part_t *sort_partition_list(list_part_t *list_part);
diff --git a/src/qphotorec.cpp b/src/qphotorec.cpp
index acb1cd3..c38599f 100644
--- a/src/qphotorec.cpp
+++ b/src/qphotorec.cpp
@@ -113,6 +113,8 @@ QPhotorec::QPhotorec(QWidget *my_parent) : QWidget(my_parent)
{
no_disk_warning();
}
+ else
+ select_disk(list_disk->disk);
setupUI();
}
@@ -147,12 +149,15 @@ void QPhotorec::newSourceFile()
"Raw Files (*.dd *.raw *.img)");
if(!filename.isEmpty())
{
+ disk_t *new_disk=NULL;
QByteArray filenameArray= (filename).toUtf8();
- list_disk=insert_new_disk(list_disk, file_test_availability(filenameArray.constData(), options->verbose, testdisk_mode));
- if(list_disk!=NULL)
- select_disk(list_disk->disk);
- HDDlistWidget_updateUI();
- PartListWidget_updateUI();
+ list_disk=insert_new_disk_aux(list_disk, file_test_availability(filenameArray.constData(), options->verbose, testdisk_mode), &new_disk);
+ if(new_disk!=NULL)
+ {
+ select_disk(new_disk);
+ HDDlistWidget_updateUI();
+ PartListWidget_updateUI();
+ }
}
}
@@ -242,6 +247,9 @@ void QPhotorec::PartListWidget_updateUI()
item=new QTableWidgetItem(QString(sizeinfo));
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
PartListWidget->setItem(currentRow, 4, item);
+ /* Select the partition if it's already known */
+ if(selected_partition == partition)
+ PartListWidget->setCurrentItem(item);
}
{
QString partname="";
@@ -274,6 +282,15 @@ void QPhotorec::select_disk(disk_t *disk)
log_info("%s\n", selected_disk->description_short(selected_disk));
part_free_list(list_part);
list_part=init_list_part(selected_disk, NULL);
+ /* If only whole disk is listed, select it */
+ /* If there is the whole disk and only one partition, select the partition */
+ if(list_part!=NULL)
+ {
+ if(list_part->next==NULL)
+ selected_partition=list_part->part;
+ else if(list_part->next->next==NULL)
+ selected_partition=list_part->next->part;
+ }
log_all_partitions(selected_disk, list_part);
}
@@ -386,13 +403,18 @@ void QPhotorec::buttons_updateUI()
void QPhotorec::HDDlistWidget_updateUI()
{
list_disk_t *element_disk;
+ int i;
HDDlistWidget->clear();
- for(element_disk=list_disk;element_disk!=NULL;element_disk=element_disk->next)
+ for(element_disk=list_disk, i=0;
+ element_disk!=NULL;
+ element_disk=element_disk->next, i++)
{
disk_t *disk=element_disk->disk;
HDDlistWidget->addItem(
QIcon::fromTheme("drive-harddisk", QIcon(":res/gnome/drive-harddisk.png")),
disk->description_short(disk));
+ if(disk==selected_disk)
+ HDDlistWidget->setCurrentIndex(i);
}
HDDlistWidget->addItem(
QIcon::fromTheme("application-x-cd-image", QIcon(":res/gnome/application-x-cd-image.png")),