bool MediaNotifier::autostart(const KFileItem &medium) { QString mimetype = medium.mimetype(); bool is_cdrom = mimetype.startsWith("cd") || mimetype.startsWith("dvd"); bool is_mounted = mimetype.endsWith("_mounted"); // We autorun only on CD/DVD or removable disks (USB, Firewire) if(!(is_cdrom || is_mounted) && mimetype != "media/removable_mounted") { return false; } // Here starts the 'Autostart Of Applications After Mount' implementation // The desktop environment MAY ignore Autostart files altogether // based on policy set by the user, system administrator or vendor. MediaManagerSettings::self()->readConfig(); if(!MediaManagerSettings::self()->autostartEnabled()) { return false; } // From now we're sure the medium is already mounted. // We can use the local path for stating, no need to use KIO here. bool local; QString path = medium.mostLocalURL(local).path(); // local is always true here... // When a new medium is mounted the root directory of the medium should // be checked for the following Autostart files in order of precedence: // .autorun, autorun, autorun.sh QStringList autorun_list; autorun_list << ".autorun" << "autorun" << "autorun.sh"; QStringList::iterator it = autorun_list.begin(); QStringList::iterator end = autorun_list.end(); for(; it != end; ++it) { if(QFile::exists(path + "/" + *it)) { return execAutorun(medium, path, *it); } } // When a new medium is mounted the root directory of the medium should // be checked for the following Autoopen files in order of precedence: // .autoopen, autoopen QStringList autoopen_list; autoopen_list << ".autoopen" << "autoopen"; it = autoopen_list.begin(); end = autoopen_list.end(); for(; it != end; ++it) { if(QFile::exists(path + "/" + *it)) { return execAutoopen(medium, path, *it); } } return false; }