Only allow empty sections to be deleted

Since not all links can be deleted, an action that deletes a section
and all the links it contains cannot be reliably implemented.
Therefore, the action will only be offered if all links have already
been deleted (or were never added in the first place).
This commit is contained in:
Maarten ter Huurne 2015-04-25 21:59:51 +02:00
parent aeb9c12f5d
commit c2759f1263
22 changed files with 13 additions and 59 deletions

View File

@ -95,7 +95,6 @@ Insert a name for the new section=Sekzio berrirako izena sartu
Insert a new name for this section=Sekzio honetarako izen berria sartu
Yes=Bai
No=Ez
You will lose all the links in this section.=Sekzio honetako esteka guztiak galduko dira
Exit=Irten
Link Scanner=Esteka bilatzailea
Scanning SD filesystem...=SD txartela arakatzen...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Introduir nom per a la nova secció
Insert a new name for this section=Introduir nou nom per a la secció
Yes=Si
No=No
You will lose all the links in this section.=Es perdran tots els enllaços d'aquesta secció.
Exit=Sortir
Link Scanner=Buscador d'enllaços
Scanning SD filesystem...=Explorant el sistema de fitxers de la SD...

View File

@ -100,7 +100,6 @@ Insert a name for the new section=Angiv navn for den nye sektion
Insert a new name for this section=Angiv nyt navn for denne sektion
Yes=Ja
No=Nej
You will lose all the links in this section.=Du vil miste alle genveje i denne sektion.
Exit=Afslut
Link Scanner=Skan genveje
Scanning SD filesystem...=Skanner SD filsystem...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Geef een naam voor de nieuwe groep
Insert a new name for this section=Geef een nieuwe naam voor deze groep
Yes=Ja
No=Nee
You will lose all the links in this section.=Alle snelkoppelingen in deze groep worden gewist.
Exit=Verlaat
Link Scanner=Snelkoppeling-Scanner
Scanning SD filesystem...=Scant het SD-bestandssysteem...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Anna uuden v<>lilehden nimi
Insert a new name for this section=Anna uusi nimi t<>lle v<>lilehdelle
Yes=Kyll<6C>
No=Ei
You will lose all the links in this section.=Menet<65>t kaikki t<>ss<73> v<>lilehdess<73> olevat linkit.
Exit=Poistu
Link Scanner=Linkkiskanneri
Scanning SD filesystem...=Skannataan SD-tiedostoj<6F>rjestelm<6C><6D>...

View File

@ -69,7 +69,6 @@ Insert a name for the new section=Saisir un nom pour cette nouvelle section
Insert a new name for this section=Saisir un nouveau nom pour cette section
Yes=Oui
No=Non
You will lose all the links in this section.=Vous perdrez tous les liens dans cette section.
Exit=Quitter
Log Viewer=Journal
Displays last launched program's output=Afficher la sortie du dernier programme lancé

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Name für die neue Sektion
Insert a new name for this section=Neuer Name für diese Sektion
Yes=Ja
No=Nein
You will lose all the links in this section.=Alle Links in dieser Sektion gehen verloren.
Exit=Beenden
Link Scanner=Links suchen
Scanning SD filesystem...=SD-Karte wird durchsucht...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Inserisci un nome per la nuova sezione
Insert a new name for this section=Inserisci un nuovo nome per questa sezione
Yes=Si
No=No
You will lose all the links in this section.=Perderai tutti i collegamenti in questa sezione.
Exit=Esci
Link Scanner=Scanner di collegamenti
Scanning SD filesystem...=Scansione del filesystem della SD...

View File

@ -69,7 +69,6 @@ Insert a name for the new section=Sett inn navn på den nye katalogen
Insert a new name for this section=Sett inn et nytt navn for denne katalogen
Yes=Ja
No=Nei
You will lose all the links in this section.=Du vil miste alle linker i denne katalogen
Exit=Utgang
Log Viewer=Logg leser
Displays last launched program's output=Viser det siste lanserte programmets utgang

View File

@ -69,7 +69,6 @@ Insert a name for the new section=Wstaw nazwę dla nowej sekcji
Insert a new name for this section=Wstaw nową nazwę dla tej sekcji
Yes=Tak
No=Nie
You will lose all the links in this section.=Wszystkie odnośniki w tej sekcji zostaną utracone.
Exit=Wyjdź
Log Viewer=Dziennik zdarzeń
Displays last launched program's output=Wyświetla wyjście ostatnio uruchamianego programu

View File

@ -70,7 +70,6 @@ Insert a name for the new section=Insira um nome para a nova seção
Insert a new name for this section=Insira um novo nome para esta seção
Yes=Sim
No=Não
You will lose all the links in this section.=Você perderá todos os atalho desta seção.
Exit=Sair
Log Viewer=Visualizador de Logs
Displays last launched program's output=Mostrar a saída do último programa executado

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Insira o nome da nova secção
Insert a new name for this section=Insira um novo nome para esta secção
Yes=Sim
No=Não
You will lose all the links in this section.=Perderá todos os links desta secção.
Exit=Sair
Link Scanner=Pesquisador de links
Scanning SD filesystem...=A pesquisar o filesystem do SD...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Впишите имя для новой сек
Insert a new name for this section=Впишите новое имя для этой секции
Yes=Да
No=Нет
You will lose all the links in this section.=Вы потеряете все ссылки в этой секции
Exit=Выход
Link Scanner=Поиск ссылок
Scanning SD filesystem...=Сканирование SD...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Zadajte názov novej sekcie
Insert a new name for this section=Zadajte nový názov pre túto sekciu
Yes=Áno
No=Nie
You will lose all the links in this section.=Stratíte všetky odkazy v tejto sekcii.
Exit=Ukončiť
Link Scanner=Vyhľadávač odkazov
Scanning SD filesystem...=Prehľadávam súborový systém na SD karte...

View File

@ -95,7 +95,6 @@ Insert a name for the new section=Insertar nombre para la nueva sección
Insert a new name for this section=Insertar nuevo nombre para la sección
Yes=Si
No=No
You will lose all the links in this section.=Se perderán todos los enlaces de esta sección.
Exit=Salir
Link Scanner=Buscador de enlaces
Scanning SD filesystem...=Explorando sistema de archivos de SD...

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Skriv in namn för den nya avdelningen
Insert a new name for this section=Skriv in namn för den här avdelningen
Yes=Ja
No=Nej
You will lose all the links in this section.=Du kommer att förlora alla länkar i den här
avdelningen.
Exit=Avsluta
Link Scanner=Länkscanner

View File

@ -97,7 +97,6 @@ Insert a name for the new section=Yeni bölüm için bir isim girin
Insert a new name for this section=Bu bölüm için yeni isim girin
Yes=Evet
No=Hayir
You will lose all the links in this section.=Bu bölümdeki tüm linkleri kaybedeceksiniz.
Exit=Çikis
Link Scanner=Link taramasi
Scanning SD filesystem...=SD karti taraniyor...

View File

@ -71,9 +71,11 @@ ContextMenu::ContextMenu(GMenu2X &gmenu2x, Menu &menu)
options.push_back(std::make_shared<MenuOption>(
tr["Add section"],
std::bind(&GMenu2X::addSection, &gmenu2x)));
options.push_back(std::make_shared<MenuOption>(
tr["Delete section"],
std::bind(&GMenu2X::deleteSection, &gmenu2x)));
if (menu.sectionLinks()->empty()) {
options.push_back(std::make_shared<MenuOption>(
tr["Delete section"],
std::bind(&GMenu2X::deleteSection, &gmenu2x)));
}
// Compute bounding box.
int w = 0;

View File

@ -1024,15 +1024,14 @@ void GMenu2X::addSection() {
}
}
void GMenu2X::deleteSection() {
MessageBox mb(*this,tr["You will lose all the links in this section."]+"\n"+tr["Are you sure?"]);
mb.setButton(InputManager::ACCEPT, tr["Yes"]);
mb.setButton(InputManager::CANCEL, tr["No"]);
if (mb.exec() == InputManager::ACCEPT) {
if (rmtree(getHome() + "/sections/" + menu->selSection()))
menu->deleteSelectedSection();
void GMenu2X::deleteSection()
{
string path = getHome() + "/sections/" + menu->selSection();
if (rmdir(path.c_str()) && errno != ENOENT) {
WARNING("Removal of section dir \"%s\" failed: %s\n",
path.c_str(), strerror(errno));
}
menu->deleteSelectedSection();
}
#ifdef ENABLE_CPUFREQ

View File

@ -71,8 +71,6 @@ private:
*/
void calcSectionRange(int &leftSection, int &rightSection);
std::vector<std::unique_ptr<Link>> *sectionLinks(int i = -1);
void readLinks();
void freeLinks();
@ -160,6 +158,7 @@ public:
void setLinkIndex(int i);
const std::vector<std::string> &getSections() { return sections; }
std::vector<std::unique_ptr<Link>> *sectionLinks(int i = -1);
};
#endif // MENU_H

View File

@ -160,34 +160,6 @@ bool fileExists(const string &file) {
return access(file.c_str(), F_OK) == 0;
}
bool rmtree(string path) {
DIR *dirp;
struct stat st;
struct dirent *dptr;
string filepath;
DEBUG("RMTREE: '%s'\n", path.c_str());
if ((dirp = opendir(path.c_str())) == NULL) return false;
if (path[path.length()-1]!='/') path += "/";
while ((dptr = readdir(dirp))) {
filepath = dptr->d_name;
if (filepath=="." || filepath=="..") continue;
filepath = path+filepath;
int statRet = stat(filepath.c_str(), &st);
if (statRet == -1) continue;
if (S_ISDIR(st.st_mode)) {
if (!rmtree(filepath)) return false;
} else {
if (unlink(filepath.c_str())!=0) return false;
}
}
closedir(dirp);
return rmdir(path.c_str())==0;
}
int constrain(int x, int imin, int imax) {
return min(imax, max(imin, x));
}

View File

@ -79,7 +79,6 @@ inline std::string trimExtension(std::string const& filename) {
}
bool fileExists(const std::string &file);
bool rmtree(std::string path);
int constrain(int x, int imin, int imax);