49 #include <sys/types.h>
60 #include <tqpushbutton.h>
61 #include <tqcheckbox.h>
62 #include <tqstrlist.h>
63 #include <tqstringlist.h>
64 #include <tqtextstream.h>
65 #include <tqpainter.h>
67 #include <tqcombobox.h>
68 #include <tqgroupbox.h>
69 #include <tqwhatsthis.h>
70 #include <tqtooltip.h>
72 #include <tqprogressbar.h>
74 #include <tqvaluevector.h>
78 #include <sys/param.h>
79 #ifdef HAVE_SYS_MOUNT_H
80 #include <sys/mount.h>
82 #ifdef HAVE_SYS_XATTR_H
83 #include <sys/xattr.h>
88 #include <kapplication.h>
91 #include <kdirwatch.h>
92 #include <kdirnotify_stub.h>
93 #include <kdiskfreesp.h>
95 #include <kdesktopfile.h>
96 #include <kicondialog.h>
98 #include <kurlrequester.h>
101 #include <kglobalsettings.h>
102 #include <kstandarddirs.h>
104 #include <kio/chmodjob.h>
105 #include <kio/renamedlg.h>
106 #include <kio/netaccess.h>
107 #include <kio/kservicetypefactory.h>
108 #include <kfiledialog.h>
109 #include <kmimetype.h>
110 #include <kmountpoint.h>
111 #include <kiconloader.h>
112 #include <kmessagebox.h>
113 #include <kservice.h>
114 #include <kcompletion.h>
115 #include <klineedit.h>
116 #include <kseparator.h>
117 #include <ksqueezedtextlabel.h>
118 #include <klibloader.h>
120 #include <kparts/componentfactory.h>
121 #include <kmetaprops.h>
122 #include <kpreviewprops.h>
123 #include <kprocess.h>
125 #include <klistview.h>
127 #include "kfilesharedlg.h"
129 #include "kpropertiesdesktopbase.h"
130 #include "kpropertiesdesktopadvbase.h"
131 #include "kpropertiesmimetypebase.h"
133 #include "kacleditwidget.h"
136 #include "kpropertiesdialog.h"
139 # include <win32_utils.h>
142 static TQString nameFromFileName(TQString nameStr)
144 if ( nameStr.endsWith(
".desktop") )
145 nameStr.truncate( nameStr.length() - 8 );
146 if ( nameStr.endsWith(
".kdelnk") )
147 nameStr.truncate( nameStr.length() - 7 );
149 nameStr = KIO::decodeFileName( nameStr );
153 mode_t KFilePermissionsPropsPlugin::fperm[3][4] = {
154 {S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID},
155 {S_IRGRP, S_IWGRP, S_IXGRP, S_ISGID},
156 {S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX}
159 class KPropertiesDialog::KPropertiesDialogPrivate
162 KPropertiesDialogPrivate()
167 ~KPropertiesDialogPrivate()
171 TQWidget* fileSharePage;
175 TQWidget* parent,
const char* name,
176 bool modal,
bool autoShow)
177 : KDialogBase (KDialogBase::Tabbed, i18n(
"Properties for %1" ).arg(KIO::decodeFileName(item->url().fileName())),
178 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
181 d =
new KPropertiesDialogPrivate;
183 m_items.append(
new KFileItem(*item) );
185 m_singleUrl = item->url();
186 assert(!m_singleUrl.isEmpty());
188 init (modal, autoShow);
192 TQWidget* parent,
const char* name,
bool modal)
193 : KDialogBase (KDialogBase::Tabbed, i18n (
"Properties for %1").arg(title),
194 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
197 d =
new KPropertiesDialogPrivate;
203 TQWidget* parent,
const char* name,
204 bool modal,
bool autoShow)
205 : KDialogBase (KDialogBase::Tabbed,
208 _items.count()>1 ? i18n(
"<never used>",
"Properties for %n Selected Items",_items.count()) :
209 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_items.first()->url().fileName())),
210 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
213 d =
new KPropertiesDialogPrivate;
215 assert( !_items.isEmpty() );
216 m_singleUrl = _items.first()->url();
217 assert(!m_singleUrl.isEmpty());
219 KFileItemListIterator it ( _items );
221 for ( ; it.current(); ++it )
222 m_items.append(
new KFileItem( **it ) );
224 init (modal, autoShow);
227 #ifndef KDE_NO_COMPAT
229 TQWidget* parent,
const char* name,
230 bool modal,
bool autoShow)
231 : KDialogBase (KDialogBase::Tabbed,
232 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_url.fileName())),
233 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
234 parent, name, modal),
237 d =
new KPropertiesDialogPrivate;
241 KIO::NetAccess::stat(_url, entry, parent);
243 m_items.append(
new KFileItem( entry, _url ) );
244 init (modal, autoShow);
249 TQWidget* parent,
const char* name,
250 bool modal,
bool autoShow)
251 : KDialogBase (KDialogBase::Tabbed,
252 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_url.fileName())),
253 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
254 parent, name, modal),
257 d =
new KPropertiesDialogPrivate;
261 KIO::NetAccess::stat(_url, entry, parent);
263 m_items.append(
new KFileItem( entry, _url ) );
264 init (modal, autoShow);
268 const TQString& _defaultName,
269 TQWidget* parent,
const char* name,
270 bool modal,
bool autoShow)
271 : KDialogBase (KDialogBase::Tabbed,
272 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_tempUrl.fileName())),
273 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
274 parent, name, modal),
276 m_singleUrl( _tempUrl ),
277 m_defaultName( _defaultName ),
278 m_currentDir( _currentDir )
280 d =
new KPropertiesDialogPrivate;
282 assert(!m_singleUrl.isEmpty());
285 m_items.append(
new KFileItem( KFileItem::Unknown, KFileItem::Unknown, m_singleUrl ) );
286 init (modal, autoShow);
290 const char* name,
bool modal)
293 TQString localPath = item->localPath();
294 if (!localPath.isEmpty())
295 return showWin32FilePropertyDialog(localPath);
302 const char* name,
bool modal)
305 if (_url.isLocalFile())
306 return showWin32FilePropertyDialog( _url.path() );
313 const char* name,
bool modal)
315 if (_items.count()==1)
321 void KPropertiesDialog::init (
bool modal,
bool autoShow)
323 m_pageList.setAutoDelete(
true );
324 m_items.setAutoDelete(
true );
339 if (d->fileSharePage) {
340 showPage( pageIndex( d->fileSharePage));
345 d->fileSharePage = page;
353 for ( it=m_pageList.first(); it != 0L; it=m_pageList.next() )
357 plugin->setFileNameReadOnly( ro );
363 void KPropertiesDialog::slotStatResult( KIO::Job * )
375 connect (plugin, TQT_SIGNAL (changed ()),
376 plugin, TQT_SLOT (setDirty ()));
378 m_pageList.append (plugin);
386 KDesktopPropsPlugin::supports( _items ) ||
387 KBindingPropsPlugin::supports( _items ) ||
388 KURLPropsPlugin::supports( _items ) ||
389 KDevicePropsPlugin::supports( _items ) ||
397 d->m_aborted =
false;
400 if ( m_pageList.first()->isA(
"KFilePropsPlugin") )
401 filePropsPlugin = static_cast<KFilePropsPlugin *>(m_pageList.first());
406 for ( page = m_pageList.first(); page != 0L; page = m_pageList.next() )
407 if ( page->isDirty() && filePropsPlugin )
409 filePropsPlugin->setDirty();
417 for ( page = m_pageList.first(); page != 0L && !d->m_aborted; page = m_pageList.next() )
418 if ( page->isDirty() )
420 kdDebug( 250 ) <<
"applying changes for " << page->className() << endl;
425 kdDebug( 250 ) <<
"skipping page " << page->className() << endl;
427 if ( !d->m_aborted && filePropsPlugin )
448 void KPropertiesDialog::insertPages()
450 if (m_items.isEmpty())
465 if ( KDesktopPropsPlugin::supports( m_items ) )
471 if ( KBindingPropsPlugin::supports( m_items ) )
477 if ( KURLPropsPlugin::supports( m_items ) )
483 if ( KDevicePropsPlugin::supports( m_items ) )
501 if ( kapp->authorizeKAction(
"sharefile") &&
502 KFileSharePropsPlugin::supports( m_items ) )
510 if ( m_items.count() != 1 )
513 KFileItem *
item = m_items.first();
514 TQString mimetype = item->mimetype();
516 if ( mimetype.isEmpty() )
519 TQString query = TQString::fromLatin1(
520 "('KPropsDlg/Plugin' in ServiceTypes) and "
521 "((not exist [X-KDE-Protocol]) or "
522 " ([X-KDE-Protocol] == '%1' ) )" ).arg(item->url().protocol());
524 kdDebug( 250 ) <<
"trader query: " << query << endl;
525 KTrader::OfferList offers = KTrader::self()->query( mimetype, query );
526 KTrader::OfferList::ConstIterator it = offers.begin();
527 KTrader::OfferList::ConstIterator end = offers.end();
528 for (; it != end; ++it )
531 ::createInstanceFromLibrary<KPropsDlgPlugin>( (*it)->library().local8Bit().data(),
533 (*it)->name().latin1() );
543 Q_ASSERT( m_items.count() == 1 );
544 kdDebug(250) <<
"KPropertiesDialog::updateUrl (pre)" << _newUrl.url() << endl;
545 KURL newUrl = _newUrl;
546 emit
saveAs(m_singleUrl, newUrl);
547 kdDebug(250) <<
"KPropertiesDialog::updateUrl (post)" << newUrl.url() << endl;
549 m_singleUrl = newUrl;
550 m_items.first()->setURL( newUrl );
551 assert(!m_singleUrl.isEmpty());
554 for ( TQPtrListIterator<KPropsDlgPlugin> it(m_pageList); it.current(); ++it )
555 if ( it.current()->isA(
"KExecPropsPlugin") ||
556 it.current()->isA(
"KURLPropsPlugin") ||
557 it.current()->isA(
"KDesktopPropsPlugin"))
560 it.current()->setDirty();
567 Q_ASSERT( m_items.count() == 1 );
568 kdDebug(250) <<
"KPropertiesDialog::rename " << _name << endl;
571 if ( !m_currentDir.isEmpty() )
573 newUrl = m_currentDir;
574 newUrl.addPath( _name );
578 TQString tmpurl = m_singleUrl.url();
579 if ( tmpurl.at(tmpurl.length() - 1) ==
'/')
581 tmpurl.truncate( tmpurl.length() - 1);
583 newUrl.setFileName( _name );
593 class KPropsDlgPlugin::KPropsDlgPluginPrivate
596 KPropsDlgPluginPrivate()
599 ~KPropsDlgPluginPrivate()
607 : TQObject( _props, 0L )
609 d =
new KPropsDlgPluginPrivate;
611 fontHeight = 2*
properties->fontMetrics().height();
615 KPropsDlgPlugin::~KPropsDlgPlugin()
624 KURL url = _item->mostLocalURL( isLocal );
629 if ( !S_ISREG( _item->mode() ) )
632 TQString t( url.path() );
635 FILE *f = fopen( TQFile::encodeName(t),
"r" );
641 return ( (_item->mimetype() ==
"application/x-desktop")
642 || (_item->mimetype() ==
"media/builtin-mydocuments")
643 || (_item->mimetype() ==
"media/builtin-mycomputer")
644 || (_item->mimetype() ==
"media/builtin-mynetworkplaces")
645 || (_item->mimetype() ==
"media/builtin-printers")
646 || (_item->mimetype() ==
"media/builtin-trash")
647 || (_item->mimetype() ==
"media/builtin-webbrowser") );
650 void KPropsDlgPlugin::setDirty(
bool b )
655 void KPropsDlgPlugin::setDirty()
660 bool KPropsDlgPlugin::isDirty()
const
667 kdWarning(250) <<
"applyChanges() not implemented in page !" << endl;
672 class KFilePropsPlugin::KFilePropsPluginPrivate
675 KFilePropsPluginPrivate()
678 dirSizeUpdateTimer = 0L;
680 m_freeSpaceLabel = 0;
682 ~KFilePropsPluginPrivate()
689 TQTimer *dirSizeUpdateTimer;
695 TQLabel *m_freeSpaceLabel;
697 TQString oldFileName;
704 d =
new KFilePropsPluginPrivate;
706 d->bIconChanged =
false;
707 d->bKDesktopMode = (TQCString(tqApp->name()) ==
"kdesktop");
709 kdDebug(250) <<
"KFilePropsPlugin::KFilePropsPlugin bMultiple=" << d->bMultiple << endl;
715 KURL url = item->mostLocalURL( isLocal );
716 bool isReallyLocal = item->url().isLocalFile();
718 kdDebug() <<
"url=" << url <<
" bDesktopFile=" << bDesktopFile <<
" isLocal=" << isLocal <<
" isReallyLocal=" << isReallyLocal << endl;
719 mode_t mode = item->mode();
720 bool hasDirs = item->isDir() && !item->isLink();
721 bool hasRoot = url.path() == TQString::fromLatin1(
"/");
722 TQString iconStr = KMimeType::iconForURL(url, mode);
725 TQString mimeComment = item->mimeComment();
726 d->mimeType = item->mimetype();
728 KIO::filesize_t totalSize = item->size(hasTotalSize);
729 TQString magicMimeComment;
731 KMimeType::Ptr magicMimeType = KMimeType::findByFileContent( url.path() );
732 if ( magicMimeType->name() != KMimeType::defaultMimeType() ) {
733 magicMimeComment = magicMimeType->comment();
738 TQString filename = TQString::null;
739 bool isTrash =
false;
740 bool isDevice =
false;
741 bool isMediaNode =
false;
742 m_bFromTemplate =
false;
745 uint iDirCount = hasDirs ? 1 : 0;
746 uint iFileCount = 1-iDirCount;
748 d->m_frame =
properties->addPage (i18n(
"&General"));
750 TQVBoxLayout *vbl =
new TQVBoxLayout( d->m_frame, 0,
751 KDialog::spacingHint(),
"vbl");
752 TQGridLayout *grid =
new TQGridLayout(0, 3);
753 grid->setColStretch(0, 0);
754 grid->setColStretch(1, 0);
755 grid->setColStretch(2, 1);
756 grid->addColSpacing(1, KDialog::spacingHint());
757 vbl->addLayout(TQT_TQLAYOUT(grid));
763 if ( !m_bFromTemplate ) {
764 isTrash = (
properties->
kurl().protocol().find(
"trash", 0,
false)==0 );
768 if (d->mimeType.startsWith(
"media/")) {
772 if ( isReallyLocal ) {
786 determineRelativePath( path );
791 if ( filename.isEmpty() ) {
792 filename = item->name();
794 m_bFromTemplate =
true;
797 d->oldFileName = filename;
800 filename = nameFromFileName( filename );
802 if ( d->bKDesktopMode && d->bDesktopFile ) {
803 KDesktopFile config( url.path(),
true );
804 if ( config.hasKey(
"Name" ) ) {
805 filename = config.readName();
815 KFileItemListIterator it( items );
816 for ( ++it ; it.current(); ++it )
818 KURL url = (*it)->url();
819 kdDebug(250) <<
"KFilePropsPlugin::KFilePropsPlugin " << url.prettyURL() << endl;
822 if ( url.isLocalFile() != isLocal )
825 bDesktopFile =
false;
826 if ( (*it)->mode() != mode )
828 if ( KMimeType::iconForURL(url, mode) != iconStr )
829 iconStr =
"kmultiple";
830 if ( url.directory() != directory )
831 directory = TQString::null;
832 if ( url.protocol() != protocol )
833 protocol = TQString::null;
834 if ( !mimeComment.isNull() && (*it)->mimeComment() != mimeComment )
835 mimeComment = TQString::null;
836 if ( isLocal && !magicMimeComment.isNull() ) {
837 KMimeType::Ptr magicMimeType = KMimeType::findByFileContent( url.path() );
838 if ( magicMimeType->comment() != magicMimeComment )
839 magicMimeComment = TQString::null;
842 if ( url.path() == TQString::fromLatin1(
"/") )
844 if ( (*it)->isDir() && !(*it)->isLink() )
853 totalSize += (*it)->size(hasSize);
854 hasTotalSize = hasTotalSize || hasSize;
859 if (!isReallyLocal && !protocol.isEmpty())
863 directory += protocol;
867 if ( !isDevice && !isMediaNode && !isTrash && (bDesktopFile || S_ISDIR(mode)) && !d->bMultiple )
870 int bsize = 66 + 2 * iconButton->style().pixelMetric(TQStyle::PM_ButtonMargin);
871 iconButton->setFixedSize(bsize, bsize);
876 TQString iconStr = KMimeType::findByURL( url, mode )->icon( url, isLocal );
877 if ( bDesktopFile && isLocal ) {
878 KDesktopFile config( url.path(), true );
879 config.setDesktopGroup();
880 iconStr = config.readEntry(
"Icon" );
881 if ( config.hasDeviceType() ) {
882 iconButton->
setIconType( KIcon::Desktop, KIcon::Device );
885 iconButton->
setIconType( KIcon::Desktop, KIcon::Application );
889 iconButton->
setIconType( KIcon::Desktop, KIcon::FileSystem );
892 iconArea = iconButton;
893 connect( iconButton, TQT_SIGNAL( iconChanged(TQString) ),
894 this, TQT_SLOT( slotIconChanged() ) );
896 TQLabel *iconLabel =
new TQLabel( d->m_frame );
897 int bsize = 66 + 2 * iconLabel->style().pixelMetric(TQStyle::PM_ButtonMargin);
898 iconLabel->setFixedSize(bsize, bsize);
901 iconLabel->setPixmap( KGlobal::iconLoader()->loadIcon( item->iconName(), KIcon::Desktop, 48) );
905 iconLabel->setPixmap( KGlobal::iconLoader()->loadIcon( iconStr, KIcon::Desktop, 48) );
907 iconArea = iconLabel;
909 grid->addWidget(iconArea, curRow, 0, Qt::AlignLeft);
911 if (d->bMultiple || isTrash || isDevice || isMediaNode || hasRoot)
913 TQLabel *lab =
new TQLabel(d->m_frame );
915 lab->setText( KIO::itemsSummaryString( iFileCount + iDirCount, iFileCount, iDirCount, 0,
false ) );
917 lab->setText( filename );
921 d->m_lined =
new KLineEdit( d->m_frame );
922 d->m_lined->setText(filename);
923 nameArea = d->m_lined;
924 d->m_lined->setFocus();
928 KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
929 if (!pattern.isEmpty() && pattern.at(0)==
'*' && pattern.find(
'*',1)==-1)
930 d->m_lined->setSelection(0, filename.length()-pattern.stripWhiteSpace().length()+1);
933 int lastDot = filename.findRev(
'.');
935 d->m_lined->setSelection(0, lastDot);
938 connect( d->m_lined, TQT_SIGNAL( textChanged(
const TQString & ) ),
939 this, TQT_SLOT( nameFileChanged(
const TQString & ) ) );
942 grid->addWidget(nameArea, curRow++, 2);
944 KSeparator* sep =
new KSeparator( KSeparator::HLine, d->m_frame);
945 grid->addMultiCellWidget(sep, curRow, curRow, 0, 2);
949 if ( !mimeComment.isEmpty() && !isDevice && !isMediaNode && !isTrash)
951 l =
new TQLabel(i18n(
"Type:"), d->m_frame );
953 grid->addWidget(l, curRow, 0);
955 TQHBox *box =
new TQHBox(d->m_frame);
957 l =
new TQLabel(mimeComment, box );
961 TQPushButton *button =
new TQPushButton(box);
963 TQIconSet iconSet = SmallIconSet(TQString::fromLatin1(
"configure"));
964 TQPixmap pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
965 button->setIconSet( iconSet );
966 button->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
967 if ( d->mimeType == KMimeType::defaultMimeType() )
968 TQToolTip::add(button, i18n(
"Create new file type"));
970 TQToolTip::add(button, i18n(
"Edit file type"));
972 connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( slotEditFileType() ));
974 if (!kapp->authorizeKAction(
"editfiletype"))
978 grid->addWidget(box, curRow++, 2);
981 if ( !magicMimeComment.isEmpty() && magicMimeComment != mimeComment )
983 l =
new TQLabel(i18n(
"Contents:"), d->m_frame );
984 grid->addWidget(l, curRow, 0);
986 l =
new TQLabel(magicMimeComment, d->m_frame );
987 grid->addWidget(l, curRow++, 2);
990 if ( !directory.isEmpty() )
992 l =
new TQLabel( i18n(
"Location:"), d->m_frame );
993 grid->addWidget(l, curRow, 0);
995 l =
new KSqueezedTextLabel( d->m_frame );
996 l->setText( directory );
997 grid->addWidget(l, curRow++, 2);
1000 if( hasDirs || hasTotalSize ) {
1001 l =
new TQLabel(i18n(
"Size:"), d->m_frame );
1002 grid->addWidget(l, curRow, 0);
1004 m_sizeLabel =
new TQLabel( d->m_frame );
1005 grid->addWidget( m_sizeLabel, curRow++, 2 );
1013 m_sizeLabel->setText(KIO::convertSizeWithBytes(totalSize));
1016 m_sizeDetermineButton = 0L;
1017 m_sizeStopButton = 0L;
1021 TQHBoxLayout * sizelay =
new TQHBoxLayout(KDialog::spacingHint());
1022 grid->addLayout( sizelay, curRow++, 2 );
1025 m_sizeDetermineButton =
new TQPushButton( i18n(
"Calculate"), d->m_frame );
1026 m_sizeStopButton =
new TQPushButton( i18n(
"Stop"), d->m_frame );
1027 connect( m_sizeDetermineButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotSizeDetermine() ) );
1028 connect( m_sizeStopButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotSizeStop() ) );
1029 sizelay->addWidget(m_sizeDetermineButton, 0);
1030 sizelay->addWidget(m_sizeStopButton, 0);
1031 sizelay->addStretch(10);
1034 if ( isLocal && !hasRoot )
1036 m_sizeDetermineButton->setText( i18n(
"Refresh") );
1037 slotSizeDetermine();
1040 m_sizeStopButton->setEnabled(
false );
1043 if (!d->bMultiple && item->isLink()) {
1044 l =
new TQLabel(i18n(
"Points to:"), d->m_frame );
1045 grid->addWidget(l, curRow, 0);
1047 l =
new KSqueezedTextLabel(item->linkDest(), d->m_frame );
1048 grid->addWidget(l, curRow++, 2);
1055 time_t tim = item->time(KIO::UDS_CREATION_TIME, hasTime);
1058 l =
new TQLabel(i18n(
"Created:"), d->m_frame );
1059 grid->addWidget(l, curRow, 0);
1061 dt.setTime_t( tim );
1062 l =
new TQLabel(KGlobal::locale()->formatDateTime(dt), d->m_frame );
1063 grid->addWidget(l, curRow++, 2);
1066 tim = item->time(KIO::UDS_MODIFICATION_TIME, hasTime);
1069 l =
new TQLabel(i18n(
"Modified:"), d->m_frame );
1070 grid->addWidget(l, curRow, 0);
1072 dt.setTime_t( tim );
1073 l =
new TQLabel(KGlobal::locale()->formatDateTime(dt), d->m_frame );
1074 grid->addWidget(l, curRow++, 2);
1077 tim = item->time(KIO::UDS_ACCESS_TIME, hasTime);
1080 l =
new TQLabel(i18n(
"Accessed:"), d->m_frame );
1081 grid->addWidget(l, curRow, 0);
1083 dt.setTime_t( tim );
1084 l =
new TQLabel(KGlobal::locale()->formatDateTime(dt), d->m_frame );
1085 grid->addWidget(l, curRow++, 2);
1089 if ( isLocal && hasDirs )
1091 sep =
new KSeparator( KSeparator::HLine, d->m_frame);
1092 grid->addMultiCellWidget(sep, curRow, curRow, 0, 2);
1095 TQString mountPoint = KIO::findPathMountPoint( url.path() );
1097 if (mountPoint !=
"/")
1099 l =
new TQLabel(i18n(
"Mounted on:"), d->m_frame );
1100 grid->addWidget(l, curRow, 0);
1102 l =
new KSqueezedTextLabel( mountPoint, d->m_frame );
1103 grid->addWidget( l, curRow++, 2 );
1106 l =
new TQLabel(i18n(
"Free disk space:"), d->m_frame );
1107 grid->addWidget(l, curRow, 0);
1109 d->m_freeSpaceLabel =
new TQLabel( d->m_frame );
1110 grid->addWidget( d->m_freeSpaceLabel, curRow++, 2 );
1113 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
1114 const unsigned long&,
const TQString& ) ),
1115 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
1116 const unsigned long&,
const TQString& ) ) );
1117 job->
readDF( mountPoint );
1128 void KFilePropsPlugin::setFileNameReadOnly(
bool ro )
1132 d->m_lined->setReadOnly( ro );
1136 TQPushButton *button =
properties->actionButton(KDialogBase::Ok);
1143 void KFilePropsPlugin::slotEditFileType()
1147 if ( d->mimeType == KMimeType::defaultMimeType() ) {
1148 int pos = d->oldFileName.findRev(
'.' );
1150 mime =
"*" + d->oldFileName.mid(pos);
1157 TQString keditfiletype = TQString::fromLatin1(
"keditfiletype");
1158 KRun::runCommand( keditfiletype
1159 +
" --parent " + TQString::number( (ulong)
properties->topLevelWidget()->winId())
1160 +
" " + KProcess::quote(mime),
1161 keditfiletype, keditfiletype );
1165 void KFilePropsPlugin::slotIconChanged()
1167 d->bIconChanged =
true;
1171 void KFilePropsPlugin::nameFileChanged(
const TQString &text )
1177 void KFilePropsPlugin::determineRelativePath(
const TQString & path )
1183 m_sRelativePath =KGlobal::dirs()->relativeLocation(
"mime", path);
1184 if (m_sRelativePath.startsWith(
"/"))
1185 m_sRelativePath = TQString::null;
1189 m_sRelativePath =KGlobal::dirs()->relativeLocation(
"apps", path);
1190 if (m_sRelativePath.startsWith(
"/"))
1192 m_sRelativePath =KGlobal::dirs()->relativeLocation(
"xdgdata-apps", path);
1193 if (m_sRelativePath.startsWith(
"/"))
1194 m_sRelativePath = TQString::null;
1196 m_sRelativePath = path;
1199 if ( m_sRelativePath.isEmpty() )
1202 kdWarning(250) <<
"Warning : editing a mimetype file out of the mimetype dirs!" << endl;
1206 void KFilePropsPlugin::slotFoundMountPoint(
const TQString&,
1207 unsigned long kBSize,
1209 unsigned long kBAvail )
1211 d->m_freeSpaceLabel->setText(
1213 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
1214 .arg(KIO::convertSizeFromKB(kBAvail))
1215 .arg(KIO::convertSizeFromKB(kBSize))
1216 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
1221 void KFilePropsPlugin::slotFoundMountPoint(
const unsigned long& kBSize,
1222 const unsigned long& ,
1223 const unsigned long& kBAvail,
1226 d->m_freeSpaceLabel->setText(
1228 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
1229 .arg(KIO::convertSizeFromKB(kBAvail))
1230 .arg(KIO::convertSizeFromKB(kBSize))
1231 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
1234 void KFilePropsPlugin::slotDirSizeUpdate()
1236 KIO::filesize_t totalSize = d->dirSizeJob->totalSize();
1237 KIO::filesize_t totalFiles = d->dirSizeJob->totalFiles();
1238 KIO::filesize_t totalSubdirs = d->dirSizeJob->totalSubdirs();
1239 m_sizeLabel->setText( i18n(
"Calculating... %1 (%2)\n%3, %4")
1240 .arg(KIO::convertSize(totalSize))
1241 .arg(KGlobal::locale()->formatNumber(totalSize, 0))
1242 .arg(i18n(
"1 file",
"%n files",totalFiles))
1243 .arg(i18n(
"1 sub-folder",
"%n sub-folders",totalSubdirs)));
1246 void KFilePropsPlugin::slotDirSizeFinished( KIO::Job * job )
1249 m_sizeLabel->setText( job->errorString() );
1252 KIO::filesize_t totalSize =
static_cast<KDirSize*
>(job)->totalSize();
1253 KIO::filesize_t totalFiles =
static_cast<KDirSize*
>(job)->totalFiles();
1254 KIO::filesize_t totalSubdirs =
static_cast<KDirSize*
>(job)->totalSubdirs();
1255 m_sizeLabel->setText( TQString::fromLatin1(
"%1 (%2)\n%3, %4")
1256 .arg(KIO::convertSize(totalSize))
1257 .arg(KGlobal::locale()->formatNumber(totalSize, 0))
1258 .arg(i18n(
"1 file",
"%n files",totalFiles))
1259 .arg(i18n(
"1 sub-folder",
"%n sub-folders",totalSubdirs)));
1261 m_sizeStopButton->setEnabled(
false);
1263 m_sizeDetermineButton->setText( i18n(
"Refresh") );
1264 m_sizeDetermineButton->setEnabled(
true);
1266 delete d->dirSizeUpdateTimer;
1267 d->dirSizeUpdateTimer = 0L;
1270 void KFilePropsPlugin::slotSizeDetermine()
1272 m_sizeLabel->setText( i18n(
"Calculating...") );
1273 kdDebug(250) <<
" KFilePropsPlugin::slotSizeDetermine() properties->item()=" <<
properties->
item() << endl;
1274 kdDebug(250) <<
" URL=" <<
properties->
item()->url().url() << endl;
1276 d->dirSizeUpdateTimer =
new TQTimer(
this);
1277 connect( d->dirSizeUpdateTimer, TQT_SIGNAL( timeout() ),
1278 TQT_SLOT( slotDirSizeUpdate() ) );
1279 d->dirSizeUpdateTimer->start(500);
1280 connect( d->dirSizeJob, TQT_SIGNAL( result( KIO::Job * ) ),
1281 TQT_SLOT( slotDirSizeFinished( KIO::Job * ) ) );
1282 m_sizeStopButton->setEnabled(
true);
1283 m_sizeDetermineButton->setEnabled(
false);
1286 if ( d->m_freeSpaceLabel )
1290 KURL url = item->mostLocalURL( isLocal );
1291 TQString mountPoint = KIO::findPathMountPoint( url.path() );
1294 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
1295 const unsigned long&,
const TQString& ) ),
1296 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
1297 const unsigned long&,
const TQString& ) ) );
1298 job->readDF( mountPoint );
1302 void KFilePropsPlugin::slotSizeStop()
1304 if ( d->dirSizeJob )
1306 m_sizeLabel->setText( i18n(
"Stopped") );
1307 d->dirSizeJob->kill();
1310 if ( d->dirSizeUpdateTimer )
1311 d->dirSizeUpdateTimer->stop();
1313 m_sizeStopButton->setEnabled(
false);
1314 m_sizeDetermineButton->setEnabled(
true);
1317 KFilePropsPlugin::~KFilePropsPlugin()
1328 void qt_enter_modal( TQWidget *widget );
1329 void qt_leave_modal( TQWidget *widget );
1333 if ( d->dirSizeJob ) {
1337 kdDebug(250) <<
"KFilePropsPlugin::applyChanges" << endl;
1339 if (nameArea->inherits(TQLINEEDIT_OBJECT_NAME_STRING))
1341 TQString n = ((TQLineEdit *) nameArea)->text();
1343 while ( n[n.length()-1].isSpace() )
1344 n.truncate( n.length() - 1 );
1347 KMessageBox::sorry(
properties, i18n(
"The new file name is empty."));
1353 kdDebug(250) <<
"oldname = " << oldName << endl;
1354 kdDebug(250) <<
"newname = " << n << endl;
1355 if ( oldName != n || m_bFromTemplate ) {
1356 KIO::Job * job = 0L;
1359 TQString newFileName = KIO::encodeFileName(n);
1360 if (d->bDesktopFile && !newFileName.endsWith(
".desktop") && !newFileName.endsWith(
".kdelnk"))
1361 newFileName +=
".desktop";
1367 if ( !m_sRelativePath.isEmpty() ) {
1371 kdDebug(250) <<
"New URL = " <<
properties->
kurl().url() << endl;
1372 kdDebug(250) <<
"old = " << oldurl.url() << endl;
1375 if ( !m_bFromTemplate ) {
1382 connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
1383 TQT_SLOT( slotCopyFinished( KIO::Job * ) ) );
1384 connect( job, TQT_SIGNAL( renamed( KIO::Job *,
const KURL &,
const KURL & ) ),
1385 TQT_SLOT( slotFileRenamed( KIO::Job *,
const KURL &,
const KURL & ) ) );
1387 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
1388 qt_enter_modal(&dummy);
1389 tqApp->enter_loop();
1390 qt_leave_modal(&dummy);
1395 if ( !m_sRelativePath.isEmpty() ) {
1401 slotCopyFinished( 0L );
1404 void KFilePropsPlugin::slotCopyFinished( KIO::Job * job )
1406 kdDebug(250) <<
"KFilePropsPlugin::slotCopyFinished" << endl;
1413 job->showErrorDialog( d->m_frame );
1425 if (KBindingPropsPlugin::supports(
properties->
items()) && !m_sRelativePath.isEmpty())
1428 newURL.setPath( locateLocal(
"mime", m_sRelativePath) );
1431 else if (d->bDesktopFile && !m_sRelativePath.isEmpty())
1433 kdDebug(250) <<
"KFilePropsPlugin::slotCopyFinished " << m_sRelativePath << endl;
1435 newURL.setPath( KDesktopFile::locateLocal(m_sRelativePath) );
1436 kdDebug(250) <<
"KFilePropsPlugin::slotCopyFinished path=" << newURL.path() << endl;
1440 if ( d->bKDesktopMode && d->bDesktopFile ) {
1442 if ( d->oldFileName !=
properties->
kurl().fileName() || m_bFromTemplate ) {
1444 TQString nameStr = nameFromFileName(
properties->
kurl().fileName());
1445 config.writeEntry(
"Name", nameStr );
1446 config.writeEntry(
"Name", nameStr,
true,
false,
true );
1451 void KFilePropsPlugin::applyIconChanges()
1454 if ( !iconButton || !d->bIconChanged )
1459 url = KIO::NetAccess::mostLocalURL( url,
properties );
1460 if (url.isLocalFile()) {
1465 path = url.path(1) + TQString::fromLatin1(
".directory");
1473 TQString str = KMimeType::findByURL( url,
1475 true )->KServiceType::icon();
1478 if ( str != iconButton->icon() )
1479 sIcon = iconButton->icon();
1482 kdDebug(250) <<
"**" << path <<
"**" << endl;
1486 if ( !sIcon.isEmpty() || f.exists() )
1488 if ( !f.open( IO_ReadWrite ) ) {
1489 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not "
1490 "have sufficient access to write to <b>%1</b>.</qt>").arg(path));
1495 KDesktopFile cfg(path);
1496 kdDebug(250) <<
"sIcon = " << (sIcon) << endl;
1497 kdDebug(250) <<
"str = " << (str) << endl;
1498 cfg.writeEntry(
"Icon", sIcon );
1504 void KFilePropsPlugin::slotFileRenamed( KIO::Job *,
const KURL &,
const KURL & newUrl )
1518 for ( KFileItemListIterator it( items ); it.current(); ++it )
1519 lst.append((*it)->url());
1520 KDirNotify_stub allDirNotify(
"*",
"KDirNotify*");
1521 allDirNotify.FilesChanged( lst );
1524 class KFilePermissionsPropsPlugin::KFilePermissionsPropsPluginPrivate
1527 KFilePermissionsPropsPluginPrivate()
1530 ~KFilePermissionsPropsPluginPrivate()
1535 TQCheckBox *cbRecursive;
1536 TQLabel *explanationLabel;
1537 TQComboBox *ownerPermCombo, *groupPermCombo, *othersPermCombo;
1538 TQCheckBox *extraCheckbox;
1539 mode_t partialPermissions;
1540 KFilePermissionsPropsPlugin::PermissionsMode pmode;
1541 bool canChangePermissions;
1543 bool hasExtendedACL;
1546 bool fileSystemSupportsACLs;
1549 #define UniOwner (S_IRUSR|S_IWUSR|S_IXUSR)
1550 #define UniGroup (S_IRGRP|S_IWGRP|S_IXGRP)
1551 #define UniOthers (S_IROTH|S_IWOTH|S_IXOTH)
1552 #define UniRead (S_IRUSR|S_IRGRP|S_IROTH)
1553 #define UniWrite (S_IWUSR|S_IWGRP|S_IWOTH)
1554 #define UniExec (S_IXUSR|S_IXGRP|S_IXOTH)
1555 #define UniSpecial (S_ISUID|S_ISGID|S_ISVTX)
1558 const mode_t KFilePermissionsPropsPlugin::permissionsMasks[3] = {UniOwner, UniGroup, UniOthers};
1559 const mode_t KFilePermissionsPropsPlugin::standardPermissions[4] = { 0, UniRead, UniRead|UniWrite, (mode_t)-1 };
1562 const char *KFilePermissionsPropsPlugin::permissionsTexts[4][4] = {
1563 { I18N_NOOP(
"Forbidden"),
1564 I18N_NOOP(
"Can Read"),
1565 I18N_NOOP(
"Can Read & Write"),
1567 { I18N_NOOP(
"Forbidden"),
1568 I18N_NOOP(
"Can View Content"),
1569 I18N_NOOP(
"Can View & Modify Content"),
1572 { I18N_NOOP(
"Forbidden"),
1573 I18N_NOOP(
"Can View Content & Read"),
1574 I18N_NOOP(
"Can View/Read & Modify/Write"),
1582 d =
new KFilePermissionsPropsPluginPrivate;
1583 d->cbRecursive = 0L;
1584 grpCombo = 0L; grpEdit = 0;
1589 bool isTrash = (
properties->
kurl().protocol().find(
"trash", 0,
false)==0 );
1590 bool IamRoot = (geteuid() == 0);
1593 bool isLink = item->isLink();
1594 bool isDir = item->isDir();
1595 bool hasDir = item->isDir();
1596 permissions = item->permissions();
1597 d->partialPermissions = permissions;
1598 d->isIrregular = isIrregular(permissions, isDir, isLink);
1599 strOwner = item->user();
1600 strGroup = item->group();
1601 d->hasExtendedACL = item->ACL().isExtended() || item->defaultACL().isValid();
1602 d->extendedACL = item->ACL();
1603 d->defaultACL = item->defaultACL();
1604 d->fileSystemSupportsACLs =
false;
1610 KFileItemListIterator it( items );
1611 for ( ++it ; it.current(); ++it )
1613 if (!d->isIrregular)
1614 d->isIrregular |= isIrregular((*it)->permissions(),
1615 (*it)->isDir() == isDir,
1616 (*it)->isLink() == isLink);
1617 d->hasExtendedACL = d->hasExtendedACL || (*it)->hasExtendedACL();
1618 if ( (*it)->isLink() != isLink )
1620 if ( (*it)->isDir() != isDir )
1622 hasDir |= (*it)->isDir();
1623 if ( (*it)->permissions() != permissions )
1625 permissions &= (*it)->permissions();
1626 d->partialPermissions |= (*it)->permissions();
1628 if ( (*it)->user() != strOwner )
1629 strOwner = TQString::null;
1630 if ( (*it)->group() != strGroup )
1631 strGroup = TQString::null;
1636 d->pmode = PermissionsOnlyLinks;
1638 d->pmode = PermissionsOnlyDirs;
1640 d->pmode = PermissionsMixed;
1642 d->pmode = PermissionsOnlyFiles;
1645 d->partialPermissions = d->partialPermissions & ~permissions;
1647 bool isMyFile =
false;
1649 if (isLocal && !strOwner.isEmpty()) {
1650 struct passwd *myself = getpwuid( geteuid() );
1653 isMyFile = (strOwner == TQString::fromLocal8Bit(myself->pw_name));
1655 kdWarning() <<
"I don't exist ?! geteuid=" << geteuid() << endl;
1663 d->canChangePermissions = (isMyFile || IamRoot) && (!isLink);
1668 d->m_frame =
properties->addPage(i18n(
"&Permissions"));
1670 TQBoxLayout *box =
new TQVBoxLayout( d->m_frame, 0, KDialog::spacingHint() );
1676 TQPushButton* pbAdvancedPerm = 0;
1679 gb =
new TQGroupBox ( 0, Qt::Vertical, i18n(
"Access Permissions"), d->m_frame );
1680 gb->layout()->setSpacing(KDialog::spacingHint());
1681 gb->layout()->setMargin(KDialog::marginHint());
1682 box->addWidget (gb);
1684 gl =
new TQGridLayout (gb->layout(), 7, 2);
1685 gl->setColStretch(1, 1);
1687 l = d->explanationLabel =
new TQLabel(
"", gb );
1689 d->explanationLabel->setText(i18n(
"This file is a link and does not have permissions.",
1690 "All files are links and do not have permissions.",
1692 else if (!d->canChangePermissions)
1693 d->explanationLabel->setText(i18n(
"Only the owner can change permissions."));
1694 gl->addMultiCellWidget(l, 0, 0, 0, 1);
1696 lbl =
new TQLabel( i18n(
"O&wner:"), gb);
1697 gl->addWidget(lbl, 1, 0);
1698 l = d->ownerPermCombo =
new TQComboBox(gb);
1700 gl->addWidget(l, 1, 1);
1701 connect(l, TQT_SIGNAL( highlighted(
int) ),
this, TQT_SIGNAL(
changed() ));
1702 TQWhatsThis::add(l, i18n(
"Specifies the actions that the owner is allowed to do."));
1704 lbl =
new TQLabel( i18n(
"Gro&up:"), gb);
1705 gl->addWidget(lbl, 2, 0);
1706 l = d->groupPermCombo =
new TQComboBox(gb);
1708 gl->addWidget(l, 2, 1);
1709 connect(l, TQT_SIGNAL( highlighted(
int) ),
this, TQT_SIGNAL(
changed() ));
1710 TQWhatsThis::add(l, i18n(
"Specifies the actions that the members of the group are allowed to do."));
1712 lbl =
new TQLabel( i18n(
"O&thers:"), gb);
1713 gl->addWidget(lbl, 3, 0);
1714 l = d->othersPermCombo =
new TQComboBox(gb);
1716 gl->addWidget(l, 3, 1);
1717 connect(l, TQT_SIGNAL( highlighted(
int) ),
this, TQT_SIGNAL(
changed() ));
1718 TQWhatsThis::add(l, i18n(
"Specifies the actions that all users, who are neither "
1719 "owner nor in the group, are allowed to do."));
1722 l = d->extraCheckbox =
new TQCheckBox(hasDir ?
1723 i18n(
"Only own&er can rename and delete folder content") :
1724 i18n(
"Is &executable"),
1726 connect( d->extraCheckbox, TQT_SIGNAL( clicked() ),
this, TQT_SIGNAL(
changed() ) );
1727 gl->addWidget(l, 4, 1);
1728 TQWhatsThis::add(l, hasDir ? i18n(
"Enable this option to allow only the folder's owner to "
1729 "delete or rename the contained files and folders. Other "
1730 "users can only add new files, which requires the 'Modify "
1731 "Content' permission.")
1732 : i18n(
"Enable this option to mark the file as executable. This only makes "
1733 "sense for programs and scripts. It is required when you want to "
1736 TQLayoutItem *spacer = TQT_TQLAYOUTITEM(
new TQSpacerItem(0, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding));
1737 gl->addMultiCell(spacer, 5, 5, 0, 1);
1739 pbAdvancedPerm =
new TQPushButton(i18n(
"A&dvanced Permissions"), gb);
1740 gl->addMultiCellWidget(pbAdvancedPerm, 6, 6, 0, 1, Qt::AlignRight);
1741 connect(pbAdvancedPerm, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotShowAdvancedPermissions() ));
1744 d->extraCheckbox = 0;
1748 gb =
new TQGroupBox ( 0, Qt::Vertical, i18n(
"Ownership"), d->m_frame );
1749 gb->layout()->setSpacing(KDialog::spacingHint());
1750 gb->layout()->setMargin(KDialog::marginHint());
1751 box->addWidget (gb);
1753 gl =
new TQGridLayout (gb->layout(), 4, 3);
1754 gl->addRowSpacing(0, 10);
1757 l =
new TQLabel( i18n(
"User:"), gb );
1758 gl->addWidget (l, 1, 0);
1765 int i, maxEntries = 1000;
1766 struct passwd *user;
1771 if (IamRoot && isLocal)
1773 usrEdit =
new KLineEdit( gb );
1774 KCompletion *kcom = usrEdit->completionObject();
1775 kcom->setOrder(KCompletion::Sorted);
1777 for (i=0; ((user = getpwent()) != 0L) && (i < maxEntries); i++)
1778 kcom->addItem(TQString::fromLatin1(user->pw_name));
1780 usrEdit->setCompletionMode((i < maxEntries) ? KGlobalSettings::CompletionAuto :
1781 KGlobalSettings::CompletionNone);
1782 usrEdit->setText(strOwner);
1783 gl->addWidget(usrEdit, 1, 1);
1784 connect( usrEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
1785 this, TQT_SIGNAL(
changed() ) );
1789 l =
new TQLabel(strOwner, gb);
1790 gl->addWidget(l, 1, 1);
1795 TQStringList groupList;
1797 user = getpwuid(geteuid());
1799 strUser = user->pw_name;
1802 gid_t *groups = NULL;
1804 struct group *mygroup;
1805 gid_t *newgroups = NULL;
1807 groups = (gid_t *) malloc(ng *
sizeof(gid_t));
1809 if (getgrouplist(strUser, user->pw_gid, groups, &ng) == -1) {
1810 newgroups = (gid_t *) malloc(ng *
sizeof(gid_t));
1811 if (newgroups != NULL) {
1814 getgrouplist(strUser, user->pw_gid, groups, &ng);
1818 for (i = 0; i < ng; i++) {
1819 mygroup = getgrgid(groups[i]);
1820 if (mygroup != NULL) groupList += TQString::fromLocal8Bit(mygroup->gr_name);
1829 ge = getgrgid (getegid());
1831 TQString name = TQString::fromLatin1(ge->gr_name);
1833 name.setNum(ge->gr_gid);
1834 if (groupList.find(name) == groupList.end())
1839 bool isMyGroup = groupList.contains(strGroup);
1845 groupList += strGroup;
1847 l =
new TQLabel( i18n(
"Group:"), gb );
1848 gl->addWidget (l, 2, 0);
1856 if (IamRoot && isLocal)
1858 grpEdit =
new KLineEdit(gb);
1859 KCompletion *kcom =
new KCompletion;
1860 kcom->setItems(groupList);
1861 grpEdit->setCompletionObject(kcom,
true);
1862 grpEdit->setAutoDeleteCompletionObject(
true );
1863 grpEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
1864 grpEdit->setText(strGroup);
1865 gl->addWidget(grpEdit, 2, 1);
1866 connect( grpEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
1867 this, TQT_SIGNAL(
changed() ) );
1869 else if ((groupList.count() > 1) && isMyFile && isLocal)
1871 grpCombo =
new TQComboBox(gb,
"combogrouplist");
1872 grpCombo->insertStringList(groupList);
1873 grpCombo->setCurrentItem(groupList.findIndex(strGroup));
1874 gl->addWidget(grpCombo, 2, 1);
1875 connect( grpCombo, TQT_SIGNAL( activated(
int ) ),
1876 this, TQT_SIGNAL(
changed() ) );
1880 l =
new TQLabel(strGroup, gb);
1881 gl->addWidget(l, 2, 1);
1884 gl->setColStretch(2, 10);
1887 if ( hasDir && !isLink && !isTrash )
1889 d->cbRecursive =
new TQCheckBox( i18n(
"Apply changes to all subfolders and their contents"), d->m_frame );
1890 connect( d->cbRecursive, TQT_SIGNAL( clicked() ),
this, TQT_SIGNAL(
changed() ) );
1891 box->addWidget( d->cbRecursive );
1894 updateAccessControls();
1897 if ( isTrash || !d->canChangePermissions )
1900 enableAccessControls(
false);
1901 if ( pbAdvancedPerm && !d->hasExtendedACL )
1902 pbAdvancedPerm->setEnabled(
false);
1905 box->addStretch (10);
1908 #ifdef USE_POSIX_ACL
1909 static bool fileSystemSupportsACL(
const TQCString& pathCString )
1911 bool fileSystemSupportsACLs =
false;
1914 fileSystemSupportsACLs = ( statfs( pathCString.data(), &buf ) == 0 ) && ( buf.f_flags & MNT_ACLS );
1916 fileSystemSupportsACLs =
1917 getxattr( pathCString.data(),
"system.posix_acl_access", NULL, 0 ) >= 0
1919 || (errno == ENODATA)
1922 || (errno == ENOATTR)
1926 return fileSystemSupportsACLs;
1931 void KFilePermissionsPropsPlugin::slotShowAdvancedPermissions() {
1933 bool isDir = (d->pmode == PermissionsOnlyDirs) || (d->pmode == PermissionsMixed);
1934 KDialogBase dlg(
properties, 0,
true, i18n(
"Advanced Permissions"),
1935 KDialogBase::Ok|KDialogBase::Cancel);
1941 TQVBox *mainVBox = dlg.makeVBoxMainWidget();
1944 gb =
new TQGroupBox ( 0, Qt::Vertical, i18n(
"Access Permissions"), mainVBox );
1945 gb->layout()->setSpacing(KDialog::spacingHint());
1946 gb->layout()->setMargin(KDialog::marginHint());
1948 gl =
new TQGridLayout (gb->layout(), 6, 6);
1949 gl->addRowSpacing(0, 10);
1951 TQValueVector<TQWidget*> theNotSpecials;
1953 l =
new TQLabel(i18n(
"Class"), gb );
1954 gl->addWidget(l, 1, 0);
1955 theNotSpecials.append( l );
1958 l =
new TQLabel( i18n(
"Show\nEntries"), gb );
1960 l =
new TQLabel( i18n(
"Read"), gb );
1961 gl->addWidget (l, 1, 1);
1962 theNotSpecials.append( l );
1963 TQString readWhatsThis;
1965 readWhatsThis = i18n(
"This flag allows viewing the content of the folder.");
1967 readWhatsThis = i18n(
"The Read flag allows viewing the content of the file.");
1968 TQWhatsThis::add(l, readWhatsThis);
1971 l =
new TQLabel( i18n(
"Write\nEntries"), gb );
1973 l =
new TQLabel( i18n(
"Write"), gb );
1974 gl->addWidget (l, 1, 2);
1975 theNotSpecials.append( l );
1976 TQString writeWhatsThis;
1978 writeWhatsThis = i18n(
"This flag allows adding, renaming and deleting of files. "
1979 "Note that deleting and renaming can be limited using the Sticky flag.");
1981 writeWhatsThis = i18n(
"The Write flag allows modifying the content of the file.");
1982 TQWhatsThis::add(l, writeWhatsThis);
1984 TQString execWhatsThis;
1986 l =
new TQLabel( i18n(
"Enter folder",
"Enter"), gb );
1987 execWhatsThis = i18n(
"Enable this flag to allow entering the folder.");
1990 l =
new TQLabel( i18n(
"Exec"), gb );
1991 execWhatsThis = i18n(
"Enable this flag to allow executing the file as a program.");
1993 TQWhatsThis::add(l, execWhatsThis);
1994 theNotSpecials.append( l );
1996 TQSize size = l->sizeHint();
1997 size.setWidth(size.width() + 15);
1998 l->setFixedSize(size);
1999 gl->addWidget (l, 1, 3);
2001 l =
new TQLabel( i18n(
"Special"), gb );
2002 gl->addMultiCellWidget(l, 1, 1, 4, 5);
2003 TQString specialWhatsThis;
2005 specialWhatsThis = i18n(
"Special flag. Valid for the whole folder, the exact "
2006 "meaning of the flag can be seen in the right hand column.");
2008 specialWhatsThis = i18n(
"Special flag. The exact meaning of the flag can be seen "
2009 "in the right hand column.");
2010 TQWhatsThis::add(l, specialWhatsThis);
2012 cl[0] =
new TQLabel( i18n(
"User"), gb );
2013 gl->addWidget (cl[0], 2, 0);
2014 theNotSpecials.append( cl[0] );
2016 cl[1] =
new TQLabel( i18n(
"Group"), gb );
2017 gl->addWidget (cl[1], 3, 0);
2018 theNotSpecials.append( cl[1] );
2020 cl[2] =
new TQLabel( i18n(
"Others"), gb );
2021 gl->addWidget (cl[2], 4, 0);
2022 theNotSpecials.append( cl[2] );
2024 l =
new TQLabel(i18n(
"Set UID"), gb);
2025 gl->addWidget(l, 2, 5);
2026 TQString setUidWhatsThis;
2028 setUidWhatsThis = i18n(
"If this flag is set, the owner of this folder will be "
2029 "the owner of all new files.");
2031 setUidWhatsThis = i18n(
"If this file is an executable and the flag is set, it will "
2032 "be executed with the permissions of the owner.");
2033 TQWhatsThis::add(l, setUidWhatsThis);
2035 l =
new TQLabel(i18n(
"Set GID"), gb);
2036 gl->addWidget(l, 3, 5);
2037 TQString setGidWhatsThis;
2039 setGidWhatsThis = i18n(
"If this flag is set, the group of this folder will be "
2040 "set for all new files.");
2042 setGidWhatsThis = i18n(
"If this file is an executable and the flag is set, it will "
2043 "be executed with the permissions of the group.");
2044 TQWhatsThis::add(l, setGidWhatsThis);
2046 l =
new TQLabel(i18n(
"File permission",
"Sticky"), gb);
2047 gl->addWidget(l, 4, 5);
2048 TQString stickyWhatsThis;
2050 stickyWhatsThis = i18n(
"If the Sticky flag is set on a folder, only the owner "
2051 "and root can delete or rename files. Otherwise everybody "
2052 "with write permissions can do this.");
2054 stickyWhatsThis = i18n(
"The Sticky flag on a file is ignored on Linux, but may "
2055 "be used on some systems");
2056 TQWhatsThis::add(l, stickyWhatsThis);
2058 mode_t aPermissions, aPartialPermissions;
2059 mode_t dummy1, dummy2;
2061 if (!d->isIrregular) {
2063 case PermissionsOnlyFiles:
2064 getPermissionMasks(aPartialPermissions,
2069 case PermissionsOnlyDirs:
2070 case PermissionsMixed:
2071 getPermissionMasks(dummy1,
2072 aPartialPermissions,
2076 case PermissionsOnlyLinks:
2077 aPermissions = UniRead | UniWrite | UniExec | UniSpecial;
2078 aPartialPermissions = 0;
2083 aPermissions = permissions;
2084 aPartialPermissions = d->partialPermissions;
2088 bool allDisable =
true;
2089 TQCheckBox *cba[3][4];
2090 for (
int row = 0; row < 3 ; ++row) {
2091 for (
int col = 0; col < 4; ++col) {
2092 TQCheckBox *cb =
new TQCheckBox( gb );
2093 if ( col != 3 ) theNotSpecials.append( cb );
2095 cb->setChecked(aPermissions & fperm[row][col]);
2096 if ( aPartialPermissions & fperm[row][col] )
2099 if( d->canChangePermissions ) {
2104 else if (d->cbRecursive && d->cbRecursive->isChecked())
2107 cb->setEnabled( d->canChangePermissions );
2108 gl->addWidget (cb, row+2, col+1);
2111 TQWhatsThis::add(cb, readWhatsThis);
2114 TQWhatsThis::add(cb, writeWhatsThis);
2117 TQWhatsThis::add(cb, execWhatsThis);
2122 TQWhatsThis::add(cb, setUidWhatsThis);
2125 TQWhatsThis::add(cb, setGidWhatsThis);
2128 TQWhatsThis::add(cb, stickyWhatsThis);
2135 gl->setColStretch(6, 10);
2137 #ifdef USE_POSIX_ACL
2138 KACLEditWidget *extendedACLs = 0;
2142 TQCString pathCString = TQFile::encodeName(
properties->
item()->url().path() );
2143 d->fileSystemSupportsACLs = fileSystemSupportsACL( pathCString );
2145 if ( d->fileSystemSupportsACLs ) {
2146 std::for_each( theNotSpecials.begin(), theNotSpecials.end(), std::mem_fun( &TQWidget::hide ) );
2147 extendedACLs =
new KACLEditWidget( mainVBox );
2148 if ( d->extendedACL.isValid() && d->extendedACL.isExtended() )
2149 extendedACLs->setACL( d->extendedACL );
2151 extendedACLs->setACL( KACL( aPermissions ) );
2153 if ( d->defaultACL.isValid() )
2154 extendedACLs->setDefaultACL( d->defaultACL );
2157 extendedACLs->setAllowDefaults(
true );
2158 if ( !d->canChangePermissions )
2159 extendedACLs->setReadOnly(
true );
2164 dlg.enableButtonOK(
false );
2167 if (dlg.exec() != KDialogBase::Accepted)
2170 mode_t andPermissions = mode_t(~0);
2171 mode_t orPermissions = 0;
2172 for (
int row = 0; row < 3; ++row)
2173 for (
int col = 0; col < 4; ++col) {
2174 switch (cba[row][col]->state())
2176 case TQCheckBox::On:
2177 orPermissions |= fperm[row][col];
2179 case TQCheckBox::Off:
2180 andPermissions &= ~fperm[row][col];
2187 d->isIrregular =
false;
2189 for (KFileItemListIterator it(items); it.current(); ++it) {
2190 if (isIrregular(((*it)->permissions() & andPermissions) | orPermissions,
2191 (*it)->isDir(), (*it)->isLink())) {
2192 d->isIrregular =
true;
2197 permissions = orPermissions;
2198 d->partialPermissions = andPermissions;
2200 #ifdef USE_POSIX_ACL
2202 if ( extendedACLs ) {
2203 d->extendedACL = extendedACLs->getACL();
2204 d->defaultACL = extendedACLs->getDefaultACL();
2205 d->hasExtendedACL = d->extendedACL.isExtended() || d->defaultACL.isValid();
2206 permissions = d->extendedACL.basePermissions();
2207 permissions |= ( andPermissions | orPermissions ) & ( S_ISUID|S_ISGID|S_ISVTX );
2211 updateAccessControls();
2220 KFilePermissionsPropsPlugin::~KFilePermissionsPropsPlugin()
2227 KFileItemList::const_iterator it = _items.constBegin();
2228 for ( ; it != _items.constEnd(); ++it ) {
2229 KFileItem *item = *it;
2230 if( !item->user().isEmpty() || !item->group().isEmpty() )
2237 void KFilePermissionsPropsPlugin::setComboContent(TQComboBox *combo, PermissionsTarget target,
2238 mode_t permissions, mode_t partial) {
2240 if (d->pmode == PermissionsOnlyLinks) {
2241 combo->insertItem(i18n(
"Link"));
2242 combo->setCurrentItem(0);
2246 mode_t tMask = permissionsMasks[target];
2248 for (textIndex = 0; standardPermissions[textIndex] != (mode_t)-1; textIndex++)
2249 if ((standardPermissions[textIndex]&tMask) == (permissions&tMask&(UniRead|UniWrite)))
2251 Q_ASSERT(standardPermissions[textIndex] != (mode_t)-1);
2253 for (
int i = 0; permissionsTexts[(int)d->pmode][i]; i++)
2254 combo->insertItem(i18n(permissionsTexts[(
int)d->pmode][i]));
2256 if (partial & tMask & ~UniExec) {
2257 combo->insertItem(i18n(
"Varying (No Change)"));
2258 combo->setCurrentItem(3);
2261 combo->setCurrentItem(textIndex);
2265 bool KFilePermissionsPropsPlugin::isIrregular(mode_t permissions,
bool isDir,
bool isLink) {
2269 mode_t p = permissions;
2270 if (p & (S_ISUID | S_ISGID))
2276 mode_t p0 = p & UniOwner;
2277 if ((p0 != 0) && (p0 != (S_IRUSR | S_IXUSR)) && (p0 != UniOwner))
2280 if ((p0 != 0) && (p0 != (S_IRGRP | S_IXGRP)) && (p0 != UniGroup))
2283 if ((p0 != 0) && (p0 != (S_IROTH | S_IXOTH)) && (p0 != UniOthers))
2291 mode_t p0 = p & UniOwner;
2292 bool usrXPossible = !p0;
2294 if ((p0 == S_IXUSR) || (p0 == (S_IWUSR | S_IXUSR)))
2296 usrXPossible =
true;
2298 else if (p0 == S_IWUSR)
2302 bool grpXPossible = !p0;
2304 if ((p0 == S_IXGRP) || (p0 == (S_IWGRP | S_IXGRP)))
2306 grpXPossible =
true;
2308 else if (p0 == S_IWGRP)
2311 grpXPossible =
true;
2314 bool othXPossible = !p0;
2316 if ((p0 == S_IXOTH) || (p0 == (S_IWOTH | S_IXOTH)))
2318 othXPossible =
true;
2320 else if (p0 == S_IWOTH)
2324 return (p & UniExec) && !(usrXPossible && grpXPossible && othXPossible);
2328 void KFilePermissionsPropsPlugin::enableAccessControls(
bool enable) {
2329 d->ownerPermCombo->setEnabled(enable);
2330 d->groupPermCombo->setEnabled(enable);
2331 d->othersPermCombo->setEnabled(enable);
2332 if (d->extraCheckbox)
2333 d->extraCheckbox->setEnabled(enable);
2334 if ( d->cbRecursive )
2335 d->cbRecursive->setEnabled(enable);
2339 void KFilePermissionsPropsPlugin::updateAccessControls() {
2340 setComboContent(d->ownerPermCombo, PermissionsOwner,
2341 permissions, d->partialPermissions);
2342 setComboContent(d->groupPermCombo, PermissionsGroup,
2343 permissions, d->partialPermissions);
2344 setComboContent(d->othersPermCombo, PermissionsOthers,
2345 permissions, d->partialPermissions);
2348 case PermissionsOnlyLinks:
2349 enableAccessControls(
false);
2351 case PermissionsOnlyFiles:
2352 enableAccessControls(d->canChangePermissions && !d->isIrregular && !d->hasExtendedACL);
2353 if (d->canChangePermissions)
2354 d->explanationLabel->setText(d->isIrregular || d->hasExtendedACL ?
2355 i18n(
"This file uses advanced permissions",
2356 "These files use advanced permissions.",
2358 if (d->partialPermissions & UniExec) {
2359 d->extraCheckbox->setTristate();
2360 d->extraCheckbox->setNoChange();
2363 d->extraCheckbox->setTristate(
false);
2364 d->extraCheckbox->setChecked(permissions & UniExec);
2367 case PermissionsOnlyDirs:
2368 enableAccessControls(d->canChangePermissions && !d->isIrregular && !d->hasExtendedACL);
2371 if ( d->cbRecursive )
2372 d->cbRecursive->setEnabled( d->canChangePermissions && !d->isIrregular );
2374 if (d->canChangePermissions)
2375 d->explanationLabel->setText(d->isIrregular || d->hasExtendedACL ?
2376 i18n(
"This folder uses advanced permissions.",
2377 "These folders use advanced permissions.",
2379 if (d->partialPermissions & S_ISVTX) {
2380 d->extraCheckbox->setTristate();
2381 d->extraCheckbox->setNoChange();
2384 d->extraCheckbox->setTristate(
false);
2385 d->extraCheckbox->setChecked(permissions & S_ISVTX);
2388 case PermissionsMixed:
2389 enableAccessControls(d->canChangePermissions && !d->isIrregular && !d->hasExtendedACL);
2390 if (d->canChangePermissions)
2391 d->explanationLabel->setText(d->isIrregular || d->hasExtendedACL ?
2392 i18n(
"These files use advanced permissions.") :
"");
2394 if (d->partialPermissions & S_ISVTX) {
2395 d->extraCheckbox->setTristate();
2396 d->extraCheckbox->setNoChange();
2399 d->extraCheckbox->setTristate(
false);
2400 d->extraCheckbox->setChecked(permissions & S_ISVTX);
2407 void KFilePermissionsPropsPlugin::getPermissionMasks(mode_t &andFilePermissions,
2408 mode_t &andDirPermissions,
2409 mode_t &orFilePermissions,
2410 mode_t &orDirPermissions) {
2411 andFilePermissions = mode_t(~UniSpecial);
2412 andDirPermissions = mode_t(~(S_ISUID|S_ISGID));
2413 orFilePermissions = 0;
2414 orDirPermissions = 0;
2418 mode_t m = standardPermissions[d->ownerPermCombo->currentItem()];
2419 if (m != (mode_t) -1) {
2420 orFilePermissions |= m & UniOwner;
2421 if ((m & UniOwner) &&
2422 ((d->pmode == PermissionsMixed) ||
2423 ((d->pmode == PermissionsOnlyFiles) && (d->extraCheckbox->state() == TQButton::NoChange))))
2424 andFilePermissions &= ~(S_IRUSR | S_IWUSR);
2426 andFilePermissions &= ~(S_IRUSR | S_IWUSR | S_IXUSR);
2427 if ((m & S_IRUSR) && (d->extraCheckbox->state() == TQButton::On))
2428 orFilePermissions |= S_IXUSR;
2431 orDirPermissions |= m & UniOwner;
2433 orDirPermissions |= S_IXUSR;
2434 andDirPermissions &= ~(S_IRUSR | S_IWUSR | S_IXUSR);
2437 m = standardPermissions[d->groupPermCombo->currentItem()];
2438 if (m != (mode_t) -1) {
2439 orFilePermissions |= m & UniGroup;
2440 if ((m & UniGroup) &&
2441 ((d->pmode == PermissionsMixed) ||
2442 ((d->pmode == PermissionsOnlyFiles) && (d->extraCheckbox->state() == TQButton::NoChange))))
2443 andFilePermissions &= ~(S_IRGRP | S_IWGRP);
2445 andFilePermissions &= ~(S_IRGRP | S_IWGRP | S_IXGRP);
2446 if ((m & S_IRGRP) && (d->extraCheckbox->state() == TQButton::On))
2447 orFilePermissions |= S_IXGRP;
2450 orDirPermissions |= m & UniGroup;
2452 orDirPermissions |= S_IXGRP;
2453 andDirPermissions &= ~(S_IRGRP | S_IWGRP | S_IXGRP);
2456 m = standardPermissions[d->othersPermCombo->currentItem()];
2457 if (m != (mode_t) -1) {
2458 orFilePermissions |= m & UniOthers;
2459 if ((m & UniOthers) &&
2460 ((d->pmode == PermissionsMixed) ||
2461 ((d->pmode == PermissionsOnlyFiles) && (d->extraCheckbox->state() == TQButton::NoChange))))
2462 andFilePermissions &= ~(S_IROTH | S_IWOTH);
2464 andFilePermissions &= ~(S_IROTH | S_IWOTH | S_IXOTH);
2465 if ((m & S_IROTH) && (d->extraCheckbox->state() == TQButton::On))
2466 orFilePermissions |= S_IXOTH;
2469 orDirPermissions |= m & UniOthers;
2471 orDirPermissions |= S_IXOTH;
2472 andDirPermissions &= ~(S_IROTH | S_IWOTH | S_IXOTH);
2475 if (((d->pmode == PermissionsMixed) || (d->pmode == PermissionsOnlyDirs)) &&
2476 (d->extraCheckbox->state() != TQButton::NoChange)) {
2477 andDirPermissions &= ~S_ISVTX;
2478 if (d->extraCheckbox->state() == TQButton::On)
2479 orDirPermissions |= S_ISVTX;
2485 mode_t orFilePermissions;
2486 mode_t orDirPermissions;
2487 mode_t andFilePermissions;
2488 mode_t andDirPermissions;
2490 if (!d->canChangePermissions)
2493 if (!d->isIrregular)
2494 getPermissionMasks(andFilePermissions,
2499 orFilePermissions = permissions;
2500 andFilePermissions = d->partialPermissions;
2501 orDirPermissions = permissions;
2502 andDirPermissions = d->partialPermissions;
2505 TQString owner, group;
2507 owner = usrEdit->text();
2509 group = grpEdit->text();
2511 group = grpCombo->currentText();
2513 if (owner == strOwner)
2514 owner = TQString::null;
2516 if (group == strGroup)
2517 group = TQString::null;
2519 bool recursive = d->cbRecursive && d->cbRecursive->isChecked();
2520 bool permissionChange =
false;
2522 KFileItemList files, dirs;
2524 for (KFileItemListIterator it(items); it.current(); ++it) {
2525 if ((*it)->isDir()) {
2527 if ((*it)->permissions() != (((*it)->permissions() & andDirPermissions) | orDirPermissions))
2528 permissionChange =
true;
2530 else if ((*it)->isFile()) {
2532 if ((*it)->permissions() != (((*it)->permissions() & andFilePermissions) | orFilePermissions))
2533 permissionChange =
true;
2537 const bool ACLChange = ( d->extendedACL !=
properties->
item()->ACL() );
2538 const bool defaultACLChange = ( d->defaultACL !=
properties->
item()->defaultACL() );
2540 if ( owner.isEmpty() && group.isEmpty() && !recursive
2541 && !permissionChange && !ACLChange && !defaultACLChange )
2545 if (files.count() > 0) {
2546 job = KIO::chmod( files, orFilePermissions, ~andFilePermissions,
2547 owner, group,
false );
2548 if ( ACLChange && d->fileSystemSupportsACLs )
2549 job->addMetaData(
"ACL_STRING", d->extendedACL.isValid()?d->extendedACL.asString():
"ACL_DELETE" );
2550 if ( defaultACLChange && d->fileSystemSupportsACLs )
2551 job->addMetaData(
"DEFAULT_ACL_STRING", d->defaultACL.isValid()?d->defaultACL.asString():
"ACL_DELETE" );
2553 connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
2554 TQT_SLOT( slotChmodResult( KIO::Job * ) ) );
2556 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
2557 qt_enter_modal(&dummy);
2558 tqApp->enter_loop();
2559 qt_leave_modal(&dummy);
2561 if (dirs.count() > 0) {
2562 job = KIO::chmod( dirs, orDirPermissions, ~andDirPermissions,
2563 owner, group, recursive );
2564 if ( ACLChange && d->fileSystemSupportsACLs )
2565 job->addMetaData(
"ACL_STRING", d->extendedACL.isValid()?d->extendedACL.asString():
"ACL_DELETE" );
2566 if ( defaultACLChange && d->fileSystemSupportsACLs )
2567 job->addMetaData(
"DEFAULT_ACL_STRING", d->defaultACL.isValid()?d->defaultACL.asString():
"ACL_DELETE" );
2569 connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
2570 TQT_SLOT( slotChmodResult( KIO::Job * ) ) );
2572 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
2573 qt_enter_modal(&dummy);
2574 tqApp->enter_loop();
2575 qt_leave_modal(&dummy);
2579 void KFilePermissionsPropsPlugin::slotChmodResult( KIO::Job * job )
2581 kdDebug(250) <<
"KFilePermissionsPropsPlugin::slotChmodResult" << endl;
2583 job->showErrorDialog( d->m_frame );
2591 class KURLPropsPlugin::KURLPropsPluginPrivate
2594 KURLPropsPluginPrivate()
2597 ~KURLPropsPluginPrivate()
2607 d =
new KURLPropsPluginPrivate;
2608 d->m_frame =
properties->addPage(i18n(
"U&RL"));
2609 TQVBoxLayout *layout =
new TQVBoxLayout(d->m_frame, 0, KDialog::spacingHint());
2612 l =
new TQLabel( d->m_frame,
"Label_1" );
2613 l->setText( i18n(
"URL:") );
2614 layout->addWidget(l);
2617 layout->addWidget(URLEdit);
2622 if ( !f.open( IO_ReadOnly ) ) {
2627 KSimpleConfig config( path );
2628 config.setDesktopGroup();
2629 URLStr = config.readPathEntry(
"URL" );
2633 if (item && item->mimetype().startsWith(
"media/builtin-")) {
2634 URLEdit->setEnabled(
false);
2637 if ( !URLStr.isNull() ) {
2638 URLEdit->
setURL( URLStr );
2641 connect( URLEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2642 this, TQT_SIGNAL(
changed() ) );
2644 layout->addStretch (1);
2647 KURLPropsPlugin::~KURLPropsPlugin()
2657 bool KURLPropsPlugin::supports( KFileItemList _items )
2659 if ( _items.count() != 1 )
2661 KFileItem * item = _items.first();
2667 KDesktopFile config( item->url().path(),
true );
2668 return config.hasLinkType();
2676 if (item && item->mimetype().startsWith(
"media/builtin-")) {
2681 if ( !f.open( IO_ReadWrite ) ) {
2682 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2683 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2688 KSimpleConfig config( path );
2689 config.setDesktopGroup();
2690 config.writeEntry(
"Type", TQString::fromLatin1(
"Link"));
2691 config.writePathEntry(
"URL", URLEdit->url() );
2694 if ( config.hasKey(
"Name") )
2696 TQString nameStr = nameFromFileName(
properties->
kurl().fileName());
2697 config.writeEntry(
"Name", nameStr );
2698 config.writeEntry(
"Name", nameStr,
true,
false,
true );
2710 class KBindingPropsPlugin::KBindingPropsPluginPrivate
2713 KBindingPropsPluginPrivate()
2716 ~KBindingPropsPluginPrivate()
2725 d =
new KBindingPropsPluginPrivate;
2726 d->m_frame =
properties->addPage(i18n(
"A&ssociation"));
2727 patternEdit =
new KLineEdit( d->m_frame,
"LineEdit_1" );
2728 commentEdit =
new KLineEdit( d->m_frame,
"LineEdit_2" );
2729 mimeEdit =
new KLineEdit( d->m_frame,
"LineEdit_3" );
2731 TQBoxLayout *mainlayout =
new TQVBoxLayout(d->m_frame, 0, KDialog::spacingHint());
2734 tmpQLabel =
new TQLabel( d->m_frame,
"Label_1" );
2735 tmpQLabel->setText( i18n(
"Pattern ( example: *.html;*.htm )") );
2736 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2737 mainlayout->addWidget(tmpQLabel, 1);
2741 patternEdit->setMaxLength( 512 );
2742 patternEdit->setMinimumSize( patternEdit->sizeHint() );
2743 patternEdit->setFixedHeight( fontHeight );
2744 mainlayout->addWidget(patternEdit, 1);
2746 tmpQLabel =
new TQLabel( d->m_frame,
"Label_2" );
2747 tmpQLabel->setText( i18n(
"Mime Type") );
2748 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2749 mainlayout->addWidget(tmpQLabel, 1);
2752 mimeEdit->setMaxLength( 256 );
2753 mimeEdit->setMinimumSize( mimeEdit->sizeHint() );
2754 mimeEdit->setFixedHeight( fontHeight );
2755 mainlayout->addWidget(mimeEdit, 1);
2757 tmpQLabel =
new TQLabel( d->m_frame,
"Label_3" );
2758 tmpQLabel->setText( i18n(
"Comment") );
2759 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2760 mainlayout->addWidget(tmpQLabel, 1);
2763 commentEdit->setMaxLength( 256 );
2764 commentEdit->setMinimumSize( commentEdit->sizeHint() );
2765 commentEdit->setFixedHeight( fontHeight );
2766 mainlayout->addWidget(commentEdit, 1);
2768 cbAutoEmbed =
new TQCheckBox( i18n(
"Left click previews"), d->m_frame,
"cbAutoEmbed" );
2769 mainlayout->addWidget(cbAutoEmbed, 1);
2771 mainlayout->addStretch (10);
2772 mainlayout->activate();
2774 TQFile f( _props->
kurl().path() );
2775 if ( !f.open( IO_ReadOnly ) )
2779 KSimpleConfig config( _props->
kurl().path() );
2780 config.setDesktopGroup();
2781 TQString patternStr = config.readEntry(
"Patterns" );
2782 TQString iconStr = config.readEntry(
"Icon" );
2783 TQString commentStr = config.readEntry(
"Comment" );
2784 m_sMimeStr = config.readEntry(
"MimeType" );
2786 if ( !patternStr.isEmpty() )
2787 patternEdit->setText( patternStr );
2788 if ( !commentStr.isEmpty() )
2789 commentEdit->setText( commentStr );
2790 if ( !m_sMimeStr.isEmpty() )
2791 mimeEdit->setText( m_sMimeStr );
2792 cbAutoEmbed->setTristate();
2793 if ( config.hasKey(
"X-KDE-AutoEmbed" ) )
2794 cbAutoEmbed->setChecked( config.readBoolEntry(
"X-KDE-AutoEmbed" ) );
2796 cbAutoEmbed->setNoChange();
2798 connect( patternEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2799 this, TQT_SIGNAL(
changed() ) );
2800 connect( commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2801 this, TQT_SIGNAL(
changed() ) );
2802 connect( mimeEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2803 this, TQT_SIGNAL(
changed() ) );
2804 connect( cbAutoEmbed, TQT_SIGNAL( toggled(
bool ) ),
2805 this, TQT_SIGNAL(
changed() ) );
2808 KBindingPropsPlugin::~KBindingPropsPlugin()
2818 bool KBindingPropsPlugin::supports( KFileItemList _items )
2820 if ( _items.count() != 1 )
2822 KFileItem * item = _items.first();
2828 KDesktopFile config( item->url().path(),
true );
2829 return config.hasMimeTypeType();
2837 if ( !f.open( IO_ReadWrite ) )
2839 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2840 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2845 KSimpleConfig config( path );
2846 config.setDesktopGroup();
2847 config.writeEntry(
"Type", TQString::fromLatin1(
"MimeType") );
2849 config.writeEntry(
"Patterns", patternEdit->text() );
2850 config.writeEntry(
"Comment", commentEdit->text() );
2851 config.writeEntry(
"Comment",
2852 commentEdit->text(),
true,
false, true );
2853 config.writeEntry(
"MimeType", mimeEdit->text() );
2854 if ( cbAutoEmbed->state() == TQButton::NoChange )
2855 config.deleteEntry(
"X-KDE-AutoEmbed",
false );
2857 config.writeEntry(
"X-KDE-AutoEmbed", cbAutoEmbed->isChecked() );
2867 class KDevicePropsPlugin::KDevicePropsPluginPrivate
2870 KDevicePropsPluginPrivate()
2873 ~KDevicePropsPluginPrivate()
2878 TQStringList mountpointlist;
2879 TQLabel *m_freeSpaceText;
2880 TQLabel *m_freeSpaceLabel;
2881 TQProgressBar *m_freeSpaceBar;
2886 d =
new KDevicePropsPluginPrivate;
2887 d->m_frame =
properties->addPage(i18n(
"De&vice"));
2889 TQStringList devices;
2890 KMountPoint::List mountPoints = KMountPoint::possibleMountPoints();
2892 for(KMountPoint::List::ConstIterator it = mountPoints.begin();
2893 it != mountPoints.end(); ++it)
2895 KMountPoint *mp = *it;
2896 TQString mountPoint = mp->mountPoint();
2897 TQString device = mp->mountedFrom();
2898 kdDebug()<<
"mountPoint :"<<mountPoint<<
" device :"<<device<<
" mp->mountType() :"<<mp->mountType()<<endl;
2900 if ((mountPoint !=
"-") && (mountPoint !=
"none") && !mountPoint.isEmpty()
2901 && device !=
"none")
2903 devices.append( device + TQString::fromLatin1(
" (")
2904 + mountPoint + TQString::fromLatin1(
")") );
2905 m_devicelist.append(device);
2906 d->mountpointlist.append(mountPoint);
2910 TQGridLayout *layout =
new TQGridLayout( d->m_frame, 0, 2, 0,
2911 KDialog::spacingHint());
2912 layout->setColStretch(1, 1);
2915 label =
new TQLabel( d->m_frame );
2916 label->setText( devices.count() == 0 ?
2917 i18n(
"Device (/dev/fd0):") :
2919 layout->addWidget(label, 0, 0);
2921 device =
new TQComboBox(
true, d->m_frame,
"ComboBox_device" );
2922 device->insertStringList( devices );
2923 layout->addWidget(device, 0, 1);
2924 connect( device, TQT_SIGNAL( activated(
int ) ),
2925 this, TQT_SLOT( slotActivated(
int ) ) );
2927 readonly =
new TQCheckBox( d->m_frame,
"CheckBox_readonly" );
2928 readonly->setText( i18n(
"Read only") );
2929 layout->addWidget(readonly, 1, 1);
2931 label =
new TQLabel( d->m_frame );
2932 label->setText( i18n(
"File system:") );
2933 layout->addWidget(label, 2, 0);
2935 TQLabel *fileSystem =
new TQLabel( d->m_frame );
2936 layout->addWidget(fileSystem, 2, 1);
2938 label =
new TQLabel( d->m_frame );
2939 label->setText( devices.count()==0 ?
2940 i18n(
"Mount point (/mnt/floppy):") :
2941 i18n(
"Mount point:"));
2942 layout->addWidget(label, 3, 0);
2944 mountpoint =
new TQLabel( d->m_frame,
"LineEdit_mountpoint" );
2946 layout->addWidget(mountpoint, 3, 1);
2949 d->m_freeSpaceText =
new TQLabel(i18n(
"Free disk space:"), d->m_frame );
2950 layout->addWidget(d->m_freeSpaceText, 4, 0);
2952 d->m_freeSpaceLabel =
new TQLabel( d->m_frame );
2953 layout->addWidget( d->m_freeSpaceLabel, 4, 1 );
2955 d->m_freeSpaceBar =
new TQProgressBar( d->m_frame,
"freeSpaceBar" );
2956 layout->addMultiCellWidget(d->m_freeSpaceBar, 5, 5, 0, 1);
2959 d->m_freeSpaceText->hide();
2960 d->m_freeSpaceLabel->hide();
2961 d->m_freeSpaceBar->hide();
2963 KSeparator* sep =
new KSeparator( KSeparator::HLine, d->m_frame);
2964 layout->addMultiCellWidget(sep, 6, 6, 0, 1);
2967 int bsize = 66 + 2 * unmounted->style().pixelMetric(TQStyle::PM_ButtonMargin);
2968 unmounted->setFixedSize(bsize, bsize);
2969 unmounted->setIconType(KIcon::Desktop, KIcon::Device);
2970 layout->addWidget(unmounted, 7, 0);
2972 label =
new TQLabel( i18n(
"Unmounted Icon"), d->m_frame );
2973 layout->addWidget(label, 7, 1);
2975 layout->setRowStretch(8, 1);
2977 TQString path( _props->
kurl().path() );
2980 if ( !f.open( IO_ReadOnly ) )
2984 KSimpleConfig config( path );
2985 config.setDesktopGroup();
2986 TQString deviceStr = config.readEntry(
"Dev" );
2987 TQString mountPointStr = config.readEntry(
"MountPoint" );
2988 bool ro = config.readBoolEntry(
"ReadOnly",
false );
2989 TQString unmountedStr = config.readEntry(
"UnmountIcon" );
2991 TQString fsType = config.readEntry(
"FSType");
2992 fileSystem->setText( (fsType.stripWhiteSpace() !=
"") ? i18n(fsType.local8Bit()) :
"" );
2994 device->setEditText( deviceStr );
2995 if ( !deviceStr.isEmpty() ) {
2997 int index = m_devicelist.findIndex(deviceStr);
3001 slotActivated( index );
3005 if ( !mountPointStr.isEmpty() )
3007 mountpoint->setText( mountPointStr );
3011 readonly->setChecked( ro );
3013 if ( unmountedStr.isEmpty() )
3014 unmountedStr = KMimeType::defaultMimeTypePtr()->KServiceType::icon();
3016 unmounted->setIcon( unmountedStr );
3018 connect( device, TQT_SIGNAL( activated(
int ) ),
3019 this, TQT_SIGNAL(
changed() ) );
3020 connect( device, TQT_SIGNAL( textChanged(
const TQString & ) ),
3021 this, TQT_SIGNAL(
changed() ) );
3022 connect( readonly, TQT_SIGNAL( toggled(
bool ) ),
3023 this, TQT_SIGNAL(
changed() ) );
3024 connect( unmounted, TQT_SIGNAL( iconChanged( TQString ) ),
3025 this, TQT_SIGNAL(
changed() ) );
3027 connect( device, TQT_SIGNAL( textChanged(
const TQString & ) ),
3028 this, TQT_SLOT( slotDeviceChanged() ) );
3033 KDevicePropsPlugin::~KDevicePropsPlugin()
3043 void KDevicePropsPlugin::processLockouts()
3045 if (device->currentText().stripWhiteSpace() !=
"")
3055 void KDevicePropsPlugin::updateInfo()
3058 d->m_freeSpaceText->hide();
3059 d->m_freeSpaceLabel->hide();
3060 d->m_freeSpaceBar->hide();
3062 if ( !mountpoint->text().isEmpty() )
3065 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
3066 const unsigned long&,
const TQString& ) ),
3067 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
3068 const unsigned long&,
const TQString& ) ) );
3070 job->
readDF( mountpoint->text() );
3076 void KDevicePropsPlugin::slotActivated(
int index )
3079 device->setEditText( m_devicelist[index] );
3080 mountpoint->setText( d->mountpointlist[index] );
3085 void KDevicePropsPlugin::slotDeviceChanged()
3088 int index = m_devicelist.findIndex( device->currentText() );
3090 mountpoint->setText( d->mountpointlist[index] );
3092 mountpoint->setText( TQString::null );
3097 void KDevicePropsPlugin::slotFoundMountPoint(
const unsigned long& kBSize,
3098 const unsigned long& ,
3099 const unsigned long& kBAvail,
3102 d->m_freeSpaceText->show();
3103 d->m_freeSpaceLabel->show();
3105 int percUsed = 100 - (int)(100.0 * kBAvail / kBSize);
3107 d->m_freeSpaceLabel->setText(
3109 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
3110 .arg(KIO::convertSizeFromKB(kBAvail))
3111 .arg(KIO::convertSizeFromKB(kBSize))
3112 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
3114 d->m_freeSpaceBar->setProgress(percUsed, 100);
3115 d->m_freeSpaceBar->show();
3118 bool KDevicePropsPlugin::supports( KFileItemList _items )
3120 if ( _items.count() != 1 )
3122 KFileItem * item = _items.first();
3127 KDesktopFile config( item->url().path(),
true );
3128 return config.hasDeviceType();
3135 if ( !f.open( IO_ReadWrite ) )
3137 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have sufficient "
3138 "access to write to <b>%1</b>.</qt>").arg(path));
3143 KSimpleConfig config( path );
3144 config.setDesktopGroup();
3145 config.writeEntry(
"Type", TQString::fromLatin1(
"FSDevice") );
3147 config.writeEntry(
"Dev", device->currentText() );
3148 config.writeEntry(
"MountPoint", mountpoint->text() );
3150 config.writeEntry(
"UnmountIcon", unmounted->icon() );
3151 kdDebug(250) <<
"unmounted->icon() = " << unmounted->icon() << endl;
3153 config.writeEntry(
"ReadOnly", readonly->isChecked() );
3169 TQFrame *frame =
properties->addPage(i18n(
"&Application"));
3170 TQVBoxLayout *mainlayout =
new TQVBoxLayout( frame, 0, KDialog::spacingHint() );
3172 w =
new KPropertiesDesktopBase(frame);
3173 mainlayout->addWidget(w);
3175 bool bKDesktopMode = (TQCString(tqApp->name()) ==
"kdesktop");
3180 w->nameEdit->hide();
3181 w->nameLabel->hide();
3184 w->pathEdit->setMode(KFile::Directory | KFile::LocalOnly);
3185 w->pathEdit->lineEdit()->setAcceptDrops(
false);
3187 connect( w->nameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3188 connect( w->genNameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3189 connect( w->commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3190 connect( w->commandEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3191 connect( w->pathEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3193 connect( w->browseButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotBrowseExec() ) );
3194 connect( w->addFiletypeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotAddFiletype() ) );
3195 connect( w->delFiletypeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotDelFiletype() ) );
3196 connect( w->advancedButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotAdvanced() ) );
3199 TQString path = _props->
kurl().path();
3201 if ( !f.open( IO_ReadOnly ) )
3205 KDesktopFile config( path );
3206 TQString nameStr = config.readName();
3207 TQString genNameStr = config.readGenericName();
3208 TQString commentStr = config.readComment();
3209 TQString commandStr = config.readPathEntry(
"Exec" );
3210 if (commandStr.left(12) ==
"ksystraycmd ")
3212 commandStr.remove(0, 12);
3213 m_systrayBool =
true;
3216 m_systrayBool =
false;
3218 m_origCommandStr = commandStr;
3219 TQString pathStr = config.readPathEntry(
"Path" );
3220 m_terminalBool = config.readBoolEntry(
"Terminal" );
3221 m_terminalOptionStr = config.readEntry(
"TerminalOptions" );
3222 m_suidBool = config.readBoolEntry(
"X-KDE-SubstituteUID" );
3223 m_suidUserStr = config.readEntry(
"X-KDE-Username" );
3224 if( config.hasKey(
"StartupNotify" ))
3225 m_startupBool = config.readBoolEntry(
"StartupNotify",
true );
3227 m_startupBool = config.readBoolEntry(
"X-KDE-StartupNotify",
true );
3228 m_dcopServiceType = config.readEntry(
"X-DCOP-ServiceType").lower();
3230 TQStringList mimeTypes = config.readListEntry(
"MimeType",
';' );
3232 if ( nameStr.isEmpty() || bKDesktopMode ) {
3238 if ( !bKDesktopMode )
3239 w->nameEdit->setText(nameStr);
3241 w->genNameEdit->setText( genNameStr );
3242 w->commentEdit->setText( commentStr );
3243 w->commandEdit->setText( commandStr );
3244 w->pathEdit->lineEdit()->setText( pathStr );
3245 w->filetypeList->setAllColumnsShowFocus(
true);
3247 KMimeType::Ptr defaultMimetype = KMimeType::defaultMimeTypePtr();
3248 for(TQStringList::ConstIterator it = mimeTypes.begin();
3249 it != mimeTypes.end(); )
3251 KMimeType::Ptr p = KMimeType::mimeType(*it);
3253 TQString preference;
3254 if (it != mimeTypes.end())
3257 (*it).toInt(&numeric);
3264 if (p && (p != defaultMimetype))
3266 new TQListViewItem(w->filetypeList, p->name(), p->comment(), preference);
3272 KDesktopPropsPlugin::~KDesktopPropsPlugin()
3276 void KDesktopPropsPlugin::slotSelectMimetype()
3278 TQListView *w = (TQListView*)sender();
3279 TQListViewItem *item = w->firstChild();
3282 if (item->isSelected())
3283 w->setSelected(item,
false);
3284 item = item->nextSibling();
3288 void KDesktopPropsPlugin::slotAddFiletype()
3290 KDialogBase dlg(w,
"KPropertiesMimetypes",
true,
3292 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
3294 KGuiItem okItem(i18n(
"&Add"), TQString::null ,
3295 i18n(
"Add the selected file types to\nthe list of supported file types."),
3296 i18n(
"Add the selected file types to\nthe list of supported file types."));
3297 dlg.setButtonOK(okItem);
3299 KPropertiesMimetypeBase *mw =
new KPropertiesMimetypeBase(&dlg);
3301 dlg.setMainWidget(mw);
3304 mw->listView->setRootIsDecorated(
true);
3305 mw->listView->setSelectionMode(TQListView::Extended);
3306 mw->listView->setAllColumnsShowFocus(
true);
3307 mw->listView->setFullWidth(
true);
3308 mw->listView->setMinimumSize(500,400);
3310 connect(mw->listView, TQT_SIGNAL(selectionChanged()),
3311 this, TQT_SLOT(slotSelectMimetype()));
3312 connect(mw->listView, TQT_SIGNAL(doubleClicked( TQListViewItem *,
const TQPoint &,
int )),
3313 &dlg, TQT_SLOT( slotOk()));
3315 TQMap<TQString,TQListViewItem*> majorMap;
3316 TQListViewItem *majorGroup;
3317 KMimeType::List mimetypes = KMimeType::allMimeTypes();
3318 TQValueListIterator<KMimeType::Ptr> it(mimetypes.begin());
3319 for (; it != mimetypes.end(); ++it) {
3320 TQString mimetype = (*it)->name();
3321 if (mimetype == KMimeType::defaultMimeType())
3323 int index = mimetype.find(
"/");
3324 TQString maj = mimetype.left(index);
3325 TQString min = mimetype.mid(index+1);
3327 TQMapIterator<TQString,TQListViewItem*> mit = majorMap.find( maj );
3328 if ( mit == majorMap.end() ) {
3329 majorGroup =
new TQListViewItem( mw->listView, maj );
3330 majorGroup->setExpandable(
true);
3331 mw->listView->setOpen(majorGroup,
true);
3332 majorMap.insert( maj, majorGroup );
3336 majorGroup = mit.data();
3339 TQListViewItem *item =
new TQListViewItem(majorGroup, min, (*it)->comment());
3340 item->setPixmap(0, (*it)->pixmap(KIcon::Small, IconSize(KIcon::Small)));
3342 TQMapIterator<TQString,TQListViewItem*> mit = majorMap.find(
"all" );
3343 if ( mit != majorMap.end())
3345 mw->listView->setCurrentItem(mit.data());
3346 mw->listView->ensureItemVisible(mit.data());
3350 if (dlg.exec() == KDialogBase::Accepted)
3352 KMimeType::Ptr defaultMimetype = KMimeType::defaultMimeTypePtr();
3353 TQListViewItem *majorItem = mw->listView->firstChild();
3356 TQString major = majorItem->text(0);
3358 TQListViewItem *minorItem = majorItem->firstChild();
3361 if (minorItem->isSelected())
3363 TQString mimetype = major +
"/" + minorItem->text(0);
3364 KMimeType::Ptr p = KMimeType::mimeType(mimetype);
3365 if (p && (p != defaultMimetype))
3367 mimetype = p->name();
3369 TQListViewItem *item = w->filetypeList->firstChild();
3372 if (mimetype == item->text(0))
3377 item = item->nextSibling();
3380 new TQListViewItem(w->filetypeList, p->name(), p->comment());
3385 minorItem = minorItem->nextSibling();
3388 majorItem = majorItem->nextSibling();
3394 void KDesktopPropsPlugin::slotDelFiletype()
3396 delete w->filetypeList->currentItem();
3400 void KDesktopPropsPlugin::checkCommandChanged()
3402 if (KRun::binaryName(w->commandEdit->text(),
true) !=
3403 KRun::binaryName(m_origCommandStr,
true))
3405 TQString m_origCommandStr = w->commandEdit->text();
3406 m_dcopServiceType= TQString::null;
3412 kdDebug(250) <<
"KDesktopPropsPlugin::applyChanges" << endl;
3417 if ( !f.open( IO_ReadWrite ) ) {
3418 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
3419 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
3426 checkCommandChanged();
3428 KSimpleConfig config( path );
3429 config.setDesktopGroup();
3430 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
3431 config.writeEntry(
"Comment", w->commentEdit->text() );
3432 config.writeEntry(
"Comment", w->commentEdit->text(),
true,
false, true );
3433 config.writeEntry(
"GenericName", w->genNameEdit->text() );
3434 config.writeEntry(
"GenericName", w->genNameEdit->text(),
true,
false, true );
3437 config.writePathEntry(
"Exec", w->commandEdit->text().prepend(
"ksystraycmd ") );
3439 config.writePathEntry(
"Exec", w->commandEdit->text() );
3440 config.writePathEntry(
"Path", w->pathEdit->lineEdit()->text() );
3443 TQStringList mimeTypes;
3444 for( TQListViewItem *item = w->filetypeList->firstChild();
3445 item; item = item->nextSibling() )
3447 TQString preference = item->text(2);
3448 mimeTypes.append(item->text(0));
3449 if (!preference.isEmpty())
3450 mimeTypes.append(preference);
3453 config.writeEntry(
"MimeType", mimeTypes,
';' );
3455 if ( !w->nameEdit->isHidden() ) {
3456 TQString nameStr = w->nameEdit->text();
3457 config.writeEntry(
"Name", nameStr );
3458 config.writeEntry(
"Name", nameStr,
true,
false,
true );
3461 config.writeEntry(
"Terminal", m_terminalBool);
3462 config.writeEntry(
"TerminalOptions", m_terminalOptionStr);
3463 config.writeEntry(
"X-KDE-SubstituteUID", m_suidBool);
3464 config.writeEntry(
"X-KDE-Username", m_suidUserStr);
3465 config.writeEntry(
"StartupNotify", m_startupBool);
3466 config.writeEntry(
"X-DCOP-ServiceType", m_dcopServiceType);
3470 TQString sycocaPath = KGlobal::dirs()->relativeLocation(
"apps", path);
3471 bool updateNeeded = !sycocaPath.startsWith(
"/");
3474 sycocaPath = KGlobal::dirs()->relativeLocation(
"xdgdata-apps", path);
3475 updateNeeded = !sycocaPath.startsWith(
"/");
3478 KService::rebuildKSycoca(w);
3482 void KDesktopPropsPlugin::slotBrowseExec()
3485 TQString::null, w );
3489 if ( !f.isLocalFile()) {
3490 KMessageBox::sorry(w, i18n(
"Only executables on local file systems are supported."));
3494 TQString path = f.path();
3495 KRun::shellQuote( path );
3496 w->commandEdit->setText( path );
3499 void KDesktopPropsPlugin::slotAdvanced()
3501 KDialogBase dlg(w,
"KPropertiesDesktopAdv",
true,
3502 i18n(
"Advanced Options for %1").arg(
properties->
kurl().fileName()),
3503 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
3504 KPropertiesDesktopAdvBase *w =
new KPropertiesDesktopAdvBase(&dlg);
3506 dlg.setMainWidget(w);
3510 checkCommandChanged();
3514 KConfigGroup confGroup( KGlobal::config(), TQString::fromLatin1(
"General") );
3515 TQString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication",
3516 TQString::fromLatin1(
"konsole"));
3518 bool terminalCloseBool =
false;
3520 if (preferredTerminal ==
"konsole")
3522 terminalCloseBool = (m_terminalOptionStr.contains(
"--noclose" ) > 0);
3523 w->terminalCloseCheck->setChecked(terminalCloseBool);
3524 m_terminalOptionStr.replace(
"--noclose",
"");
3528 w->terminalCloseCheck->hide();
3531 w->terminalCheck->setChecked(m_terminalBool);
3532 w->terminalEdit->setText(m_terminalOptionStr);
3533 w->terminalCloseCheck->setEnabled(m_terminalBool);
3534 w->terminalEdit->setEnabled(m_terminalBool);
3535 w->terminalEditLabel->setEnabled(m_terminalBool);
3537 w->suidCheck->setChecked(m_suidBool);
3538 w->suidEdit->setText(m_suidUserStr);
3539 w->suidEdit->setEnabled(m_suidBool);
3540 w->suidEditLabel->setEnabled(m_suidBool);
3542 w->startupInfoCheck->setChecked(m_startupBool);
3543 w->systrayCheck->setChecked(m_systrayBool);
3545 if (m_dcopServiceType ==
"unique")
3546 w->dcopCombo->setCurrentItem(2);
3547 else if (m_dcopServiceType ==
"multi")
3548 w->dcopCombo->setCurrentItem(1);
3549 else if (m_dcopServiceType ==
"wait")
3550 w->dcopCombo->setCurrentItem(3);
3552 w->dcopCombo->setCurrentItem(0);
3555 KCompletion *kcom =
new KCompletion;
3556 kcom->setOrder(KCompletion::Sorted);
3558 int i, maxEntries = 1000;
3560 for (i=0; ((pw = getpwent()) != 0L) && (i < maxEntries); i++)
3561 kcom->addItem(TQString::fromLatin1(pw->pw_name));
3565 w->suidEdit->setCompletionObject(kcom,
true);
3566 w->suidEdit->setAutoDeleteCompletionObject(
true );
3567 w->suidEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
3574 connect( w->terminalEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3575 this, TQT_SIGNAL(
changed() ) );
3576 connect( w->terminalCloseCheck, TQT_SIGNAL( toggled(
bool ) ),
3577 this, TQT_SIGNAL(
changed() ) );
3578 connect( w->terminalCheck, TQT_SIGNAL( toggled(
bool ) ),
3579 this, TQT_SIGNAL(
changed() ) );
3580 connect( w->suidCheck, TQT_SIGNAL( toggled(
bool ) ),
3581 this, TQT_SIGNAL(
changed() ) );
3582 connect( w->suidEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3583 this, TQT_SIGNAL(
changed() ) );
3584 connect( w->startupInfoCheck, TQT_SIGNAL( toggled(
bool ) ),
3585 this, TQT_SIGNAL(
changed() ) );
3586 connect( w->systrayCheck, TQT_SIGNAL( toggled(
bool ) ),
3587 this, TQT_SIGNAL(
changed() ) );
3588 connect( w->dcopCombo, TQT_SIGNAL( highlighted(
int ) ),
3589 this, TQT_SIGNAL(
changed() ) );
3591 if ( dlg.exec() == TQDialog::Accepted )
3593 m_terminalOptionStr = w->terminalEdit->text().stripWhiteSpace();
3594 m_terminalBool = w->terminalCheck->isChecked();
3595 m_suidBool = w->suidCheck->isChecked();
3596 m_suidUserStr = w->suidEdit->text().stripWhiteSpace();
3597 m_startupBool = w->startupInfoCheck->isChecked();
3598 m_systrayBool = w->systrayCheck->isChecked();
3600 if (w->terminalCloseCheck->isChecked())
3602 m_terminalOptionStr.append(
" --noclose");
3605 switch(w->dcopCombo->currentItem())
3607 case 1: m_dcopServiceType =
"multi";
break;
3608 case 2: m_dcopServiceType =
"unique";
break;
3609 case 3: m_dcopServiceType =
"wait";
break;
3610 default: m_dcopServiceType =
"none";
break;
3615 bool KDesktopPropsPlugin::supports( KFileItemList _items )
3617 if ( _items.count() != 1 )
3619 KFileItem * item = _items.first();
3624 KDesktopFile config( item->url().path(),
true );
3625 return config.hasApplicationType() && kapp->authorize(
"run_desktop_files") && kapp->authorize(
"shell_access");
3628 void KPropertiesDialog::virtual_hook(
int id,
void* data )
3629 { KDialogBase::virtual_hook(
id, data ); }
3631 void KPropsDlgPlugin::virtual_hook(
int,
void* )
3643 class KExecPropsPlugin::KExecPropsPluginPrivate
3646 KExecPropsPluginPrivate()
3649 ~KExecPropsPluginPrivate()
3654 TQCheckBox *nocloseonexitCheck;
3660 d =
new KExecPropsPluginPrivate;
3661 d->m_frame =
properties->addPage(i18n(
"E&xecute"));
3662 TQVBoxLayout * mainlayout =
new TQVBoxLayout( d->m_frame, 0,
3663 KDialog::spacingHint());
3668 l =
new TQLabel( i18n(
"Comman&d:" ), d->m_frame );
3669 mainlayout->addWidget(l);
3671 TQHBoxLayout * hlayout;
3672 hlayout =
new TQHBoxLayout(KDialog::spacingHint());
3673 mainlayout->addLayout(hlayout);
3675 execEdit =
new KLineEdit( d->m_frame );
3676 TQWhatsThis::add(execEdit,i18n(
3677 "Following the command, you can have several place holders which will be replaced "
3678 "with the actual values when the actual program is run:\n"
3679 "%f - a single file name\n"
3680 "%F - a list of files; use for applications that can open several local files at once\n"
3681 "%u - a single URL\n"
3682 "%U - a list of URLs\n"
3683 "%d - the folder of the file to open\n"
3684 "%D - a list of folders\n"
3686 "%m - the mini-icon\n"
3687 "%c - the caption"));
3688 hlayout->addWidget(execEdit, 1);
3690 l->setBuddy( execEdit );
3692 execBrowse =
new TQPushButton( d->m_frame );
3693 execBrowse->setText( i18n(
"&Browse...") );
3694 hlayout->addWidget(execBrowse);
3697 TQGroupBox* tmpQGroupBox;
3698 tmpQGroupBox =
new TQGroupBox( i18n(
"Panel Embedding"), d->m_frame );
3699 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3701 mainlayout->addWidget(tmpQGroupBox);
3703 TQGridLayout *grid =
new TQGridLayout(tmpQGroupBox->layout(), 2, 2);
3704 grid->setSpacing( KDialog::spacingHint() );
3705 grid->setColStretch(1, 1);
3707 l =
new TQLabel( i18n(
"&Execute on click:" ), tmpQGroupBox );
3708 grid->addWidget(l, 0, 0);
3710 swallowExecEdit =
new KLineEdit( tmpQGroupBox );
3711 grid->addWidget(swallowExecEdit, 0, 1);
3713 l->setBuddy( swallowExecEdit );
3715 l =
new TQLabel( i18n(
"&Window title:" ), tmpQGroupBox );
3716 grid->addWidget(l, 1, 0);
3718 swallowTitleEdit =
new KLineEdit( tmpQGroupBox );
3719 grid->addWidget(swallowTitleEdit, 1, 1);
3721 l->setBuddy( swallowTitleEdit );
3725 tmpQGroupBox =
new TQGroupBox( d->m_frame );
3726 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3728 mainlayout->addWidget(tmpQGroupBox);
3730 grid =
new TQGridLayout(tmpQGroupBox->layout(), 3, 2);
3731 grid->setSpacing( KDialog::spacingHint() );
3732 grid->setColStretch(1, 1);
3734 terminalCheck =
new TQCheckBox( tmpQGroupBox );
3735 terminalCheck->setText( i18n(
"&Run in terminal") );
3736 grid->addMultiCellWidget(terminalCheck, 0, 0, 0, 1);
3740 KConfigGroup confGroup( KGlobal::config(), TQString::fromLatin1(
"General") );
3741 TQString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication",
3742 TQString::fromLatin1(
"konsole"));
3745 d->nocloseonexitCheck = 0L;
3746 if (preferredTerminal ==
"konsole")
3749 d->nocloseonexitCheck =
new TQCheckBox( tmpQGroupBox );
3750 d->nocloseonexitCheck->setText( i18n(
"Do not &close when command exits") );
3751 grid->addMultiCellWidget(d->nocloseonexitCheck, 1, 1, 0, 1);
3754 terminalLabel =
new TQLabel( i18n(
"&Terminal options:" ), tmpQGroupBox );
3755 grid->addWidget(terminalLabel, posOptions, 0);
3757 terminalEdit =
new KLineEdit( tmpQGroupBox );
3758 grid->addWidget(terminalEdit, posOptions, 1);
3760 terminalLabel->setBuddy( terminalEdit );
3764 tmpQGroupBox =
new TQGroupBox( d->m_frame );
3765 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3767 mainlayout->addWidget(tmpQGroupBox);
3769 grid =
new TQGridLayout(tmpQGroupBox->layout(), 2, 2);
3770 grid->setSpacing(KDialog::spacingHint());
3771 grid->setColStretch(1, 1);
3773 suidCheck =
new TQCheckBox(tmpQGroupBox);
3774 suidCheck->setText(i18n(
"Ru&n as a different user"));
3775 grid->addMultiCellWidget(suidCheck, 0, 0, 0, 1);
3777 suidLabel =
new TQLabel(i18n(
"&Username:" ), tmpQGroupBox);
3778 grid->addWidget(suidLabel, 1, 0);
3780 suidEdit =
new KLineEdit(tmpQGroupBox);
3781 grid->addWidget(suidEdit, 1, 1);
3783 suidLabel->setBuddy( suidEdit );
3785 mainlayout->addStretch(1);
3788 TQString path = _props->
kurl().path();
3790 if ( !f.open( IO_ReadOnly ) )
3794 KSimpleConfig config( path );
3795 config.setDollarExpansion(
false );
3796 config.setDesktopGroup();
3797 execStr = config.readPathEntry(
"Exec" );
3798 swallowExecStr = config.readPathEntry(
"SwallowExec" );
3799 swallowTitleStr = config.readEntry(
"SwallowTitle" );
3800 termBool = config.readBoolEntry(
"Terminal" );
3801 termOptionsStr = config.readEntry(
"TerminalOptions" );
3802 suidBool = config.readBoolEntry(
"X-KDE-SubstituteUID" );
3803 suidUserStr = config.readEntry(
"X-KDE-Username" );
3805 if ( !swallowExecStr.isNull() )
3806 swallowExecEdit->setText( swallowExecStr );
3807 if ( !swallowTitleStr.isNull() )
3808 swallowTitleEdit->setText( swallowTitleStr );
3810 if ( !execStr.isNull() )
3811 execEdit->setText( execStr );
3813 if ( d->nocloseonexitCheck )
3815 d->nocloseonexitCheck->setChecked( (termOptionsStr.contains(
"--noclose" ) > 0) );
3816 termOptionsStr.replace(
"--noclose",
"");
3818 if ( !termOptionsStr.isNull() )
3819 terminalEdit->setText( termOptionsStr );
3821 terminalCheck->setChecked( termBool );
3822 enableCheckedEdit();
3824 suidCheck->setChecked( suidBool );
3825 suidEdit->setText( suidUserStr );
3829 KCompletion *kcom =
new KCompletion;
3830 kcom->setOrder(KCompletion::Sorted);
3832 int i, maxEntries = 1000;
3834 for (i=0; ((pw = getpwent()) != 0L) && (i < maxEntries); i++)
3835 kcom->addItem(TQString::fromLatin1(pw->pw_name));
3839 suidEdit->setCompletionObject(kcom,
true);
3840 suidEdit->setAutoDeleteCompletionObject(
true );
3841 suidEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
3848 connect( swallowExecEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3849 this, TQT_SIGNAL(
changed() ) );
3850 connect( swallowTitleEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3851 this, TQT_SIGNAL(
changed() ) );
3852 connect( execEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3853 this, TQT_SIGNAL(
changed() ) );
3854 connect( terminalEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3855 this, TQT_SIGNAL(
changed() ) );
3856 if (d->nocloseonexitCheck)
3857 connect( d->nocloseonexitCheck, TQT_SIGNAL( toggled(
bool ) ),
3858 this, TQT_SIGNAL(
changed() ) );
3859 connect( terminalCheck, TQT_SIGNAL( toggled(
bool ) ),
3860 this, TQT_SIGNAL(
changed() ) );
3861 connect( suidCheck, TQT_SIGNAL( toggled(
bool ) ),
3862 this, TQT_SIGNAL(
changed() ) );
3863 connect( suidEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3864 this, TQT_SIGNAL(
changed() ) );
3866 connect( execBrowse, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotBrowseExec() ) );
3867 connect( terminalCheck, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( enableCheckedEdit() ) );
3868 connect( suidCheck, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( enableSuidEdit() ) );
3872 KExecPropsPlugin::~KExecPropsPlugin()
3877 void KExecPropsPlugin::enableCheckedEdit()
3879 bool checked = terminalCheck->isChecked();
3880 terminalLabel->setEnabled( checked );
3881 if (d->nocloseonexitCheck)
3882 d->nocloseonexitCheck->setEnabled( checked );
3883 terminalEdit->setEnabled( checked );
3886 void KExecPropsPlugin::enableSuidEdit()
3888 bool checked = suidCheck->isChecked();
3889 suidLabel->setEnabled( checked );
3890 suidEdit->setEnabled( checked );
3893 bool KExecPropsPlugin::supports( KFileItemList _items )
3895 if ( _items.count() != 1 )
3897 KFileItem * item = _items.first();
3902 KDesktopFile config( item->url().path(),
true );
3903 return config.hasApplicationType() && kapp->authorize(
"run_desktop_files") && kapp->authorize(
"shell_access");
3908 kdDebug(250) <<
"KExecPropsPlugin::applyChanges" << endl;
3913 if ( !f.open( IO_ReadWrite ) ) {
3914 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
3915 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
3920 KSimpleConfig config( path );
3921 config.setDesktopGroup();
3922 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
3923 config.writePathEntry(
"Exec", execEdit->text() );
3924 config.writePathEntry(
"SwallowExec", swallowExecEdit->text() );
3925 config.writeEntry(
"SwallowTitle", swallowTitleEdit->text() );
3926 config.writeEntry(
"Terminal", terminalCheck->isChecked() );
3927 TQString temp = terminalEdit->text();
3928 if (d->nocloseonexitCheck )
3929 if ( d->nocloseonexitCheck->isChecked() )
3930 temp += TQString::fromLatin1(
"--noclose ");
3931 temp = temp.stripWhiteSpace();
3932 config.writeEntry(
"TerminalOptions", temp );
3933 config.writeEntry(
"X-KDE-SubstituteUID", suidCheck->isChecked() );
3934 config.writeEntry(
"X-KDE-Username", suidEdit->text() );
3938 void KExecPropsPlugin::slotBrowseExec()
3941 TQString::null, d->m_frame );
3945 if ( !f.isLocalFile()) {
3946 KMessageBox::sorry(d->m_frame, i18n(
"Only executables on local file systems are supported."));
3950 TQString path = f.path();
3951 KRun::shellQuote( path );
3952 execEdit->setText( path );
3955 class KApplicationPropsPlugin::KApplicationPropsPluginPrivate
3958 KApplicationPropsPluginPrivate()
3960 m_kdesktopMode = TQCString(tqApp->name()) ==
"kdesktop";
3962 ~KApplicationPropsPluginPrivate()
3967 bool m_kdesktopMode;
3973 d =
new KApplicationPropsPluginPrivate;
3974 d->m_frame =
properties->addPage(i18n(
"&Application"));
3975 TQVBoxLayout *toplayout =
new TQVBoxLayout( d->m_frame, 0, KDialog::spacingHint());
3980 addExtensionButton =
new TQPushButton( TQString::null, d->m_frame );
3981 iconSet = SmallIconSet(
"back" );
3982 addExtensionButton->setIconSet( iconSet );
3983 pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
3984 addExtensionButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
3985 connect( addExtensionButton, TQT_SIGNAL( clicked() ),
3986 TQT_SLOT( slotAddExtension() ) );
3988 delExtensionButton =
new TQPushButton( TQString::null, d->m_frame );
3989 iconSet = SmallIconSet(
"forward" );
3990 delExtensionButton->setIconSet( iconSet );
3991 delExtensionButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
3992 connect( delExtensionButton, TQT_SIGNAL( clicked() ),
3993 TQT_SLOT( slotDelExtension() ) );
3997 TQGridLayout *grid =
new TQGridLayout(2, 2);
3998 grid->setColStretch(1, 1);
3999 toplayout->addLayout(TQT_TQLAYOUT(grid));
4001 if ( d->m_kdesktopMode )
4008 l =
new TQLabel(i18n(
"Name:"), d->m_frame,
"Label_4" );
4009 grid->addWidget(l, 0, 0);
4011 nameEdit =
new KLineEdit( d->m_frame,
"LineEdit_3" );
4012 grid->addWidget(nameEdit, 0, 1);
4015 l =
new TQLabel(i18n(
"Description:"), d->m_frame,
"Label_5" );
4016 grid->addWidget(l, 1, 0);
4018 genNameEdit =
new KLineEdit( d->m_frame,
"LineEdit_4" );
4019 grid->addWidget(genNameEdit, 1, 1);
4021 l =
new TQLabel(i18n(
"Comment:"), d->m_frame,
"Label_3" );
4022 grid->addWidget(l, 2, 0);
4024 commentEdit =
new KLineEdit( d->m_frame,
"LineEdit_2" );
4025 grid->addWidget(commentEdit, 2, 1);
4027 l =
new TQLabel(i18n(
"File types:"), d->m_frame);
4028 toplayout->addWidget(l, 0, AlignLeft);
4030 grid =
new TQGridLayout(4, 3);
4031 grid->setColStretch(0, 1);
4032 grid->setColStretch(2, 1);
4033 grid->setRowStretch( 0, 1 );
4034 grid->setRowStretch( 3, 1 );
4035 toplayout->addLayout(TQT_TQLAYOUT(grid), 2);
4037 extensionsList =
new TQListBox( d->m_frame );
4038 extensionsList->setSelectionMode( TQListBox::Extended );
4039 grid->addMultiCellWidget(extensionsList, 0, 3, 0, 0);
4041 grid->addWidget(addExtensionButton, 1, 1);
4042 grid->addWidget(delExtensionButton, 2, 1);
4044 availableExtensionsList =
new TQListBox( d->m_frame );
4045 availableExtensionsList->setSelectionMode( TQListBox::Extended );
4046 grid->addMultiCellWidget(availableExtensionsList, 0, 3, 2, 2);
4050 if ( !f.open( IO_ReadOnly ) )
4054 KDesktopFile config( path );
4055 TQString commentStr = config.readComment();
4056 TQString genNameStr = config.readGenericName();
4058 TQStringList selectedTypes = config.readListEntry(
"ServiceTypes" );
4060 selectedTypes += config.readListEntry(
"MimeType",
';' );
4062 TQString nameStr = config.readName();
4063 if ( nameStr.isEmpty() || d->m_kdesktopMode ) {
4070 commentEdit->setText( commentStr );
4071 genNameEdit->setText( genNameStr );
4073 nameEdit->setText( nameStr );
4075 selectedTypes.sort();
4076 TQStringList::Iterator sit = selectedTypes.begin();
4077 for( ; sit != selectedTypes.end(); ++sit ) {
4078 if ( !((*sit).isEmpty()) )
4079 extensionsList->insertItem( *sit );
4082 KMimeType::List mimeTypes = KMimeType::allMimeTypes();
4083 TQValueListIterator<KMimeType::Ptr> it2 = mimeTypes.begin();
4084 for ( ; it2 != mimeTypes.end(); ++it2 )
4085 addMimeType ( (*it2)->name() );
4089 connect( extensionsList, TQT_SIGNAL( highlighted(
int ) ),
4090 this, TQT_SLOT( updateButton() ) );
4091 connect( availableExtensionsList, TQT_SIGNAL( highlighted(
int ) ),
4092 this, TQT_SLOT( updateButton() ) );
4094 connect( addExtensionButton, TQT_SIGNAL( clicked() ),
4095 this, TQT_SIGNAL(
changed() ) );
4096 connect( delExtensionButton, TQT_SIGNAL( clicked() ),
4097 this, TQT_SIGNAL(
changed() ) );
4099 connect( nameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4100 this, TQT_SIGNAL(
changed() ) );
4101 connect( commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4102 this, TQT_SIGNAL(
changed() ) );
4103 connect( genNameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4104 this, TQT_SIGNAL(
changed() ) );
4105 connect( availableExtensionsList, TQT_SIGNAL( selected(
int ) ),
4106 this, TQT_SIGNAL(
changed() ) );
4107 connect( extensionsList, TQT_SIGNAL( selected(
int ) ),
4108 this, TQT_SIGNAL(
changed() ) );
4111 KApplicationPropsPlugin::~KApplicationPropsPlugin()
4121 void KApplicationPropsPlugin::updateButton()
4123 addExtensionButton->setEnabled(availableExtensionsList->currentItem()>-1);
4124 delExtensionButton->setEnabled(extensionsList->currentItem()>-1);
4127 void KApplicationPropsPlugin::addMimeType(
const TQString & name )
4133 for ( uint i = 0; i < extensionsList->count(); i++ )
4134 if ( extensionsList->text( i ) == name )
4139 availableExtensionsList->insertItem( name );
4140 availableExtensionsList->sort();
4144 bool KApplicationPropsPlugin::supports( KFileItemList _items )
4147 return KExecPropsPlugin::supports( _items );
4156 if ( !f.open( IO_ReadWrite ) ) {
4157 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not "
4158 "have sufficient access to write to <b>%1</b>.</qt>").arg(path));
4163 KSimpleConfig config( path );
4164 config.setDesktopGroup();
4165 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
4166 config.writeEntry(
"Comment", commentEdit->text() );
4167 config.writeEntry(
"Comment", commentEdit->text(),
true,
false, true );
4168 config.writeEntry(
"GenericName", genNameEdit->text() );
4169 config.writeEntry(
"GenericName", genNameEdit->text(),
true,
false, true );
4171 TQStringList selectedTypes;
4172 for ( uint i = 0; i < extensionsList->count(); i++ )
4173 selectedTypes.append( extensionsList->text( i ) );
4175 config.writeEntry(
"MimeType", selectedTypes,
';' );
4176 config.writeEntry(
"ServiceTypes",
"" );
4179 TQString nameStr = nameEdit ? nameEdit->text() : TQString::null;
4180 if ( nameStr.isEmpty() )
4183 config.writeEntry(
"Name", nameStr );
4184 config.writeEntry(
"Name", nameStr,
true,
false,
true );
4189 void KApplicationPropsPlugin::slotAddExtension()
4191 TQListBoxItem *item = availableExtensionsList->firstItem();
4192 TQListBoxItem *nextItem;
4196 nextItem = item->next();
4198 if ( item->isSelected() )
4200 extensionsList->insertItem( item->text() );
4201 availableExtensionsList->removeItem( availableExtensionsList->index( item ) );
4207 extensionsList->sort();
4211 void KApplicationPropsPlugin::slotDelExtension()
4213 TQListBoxItem *item = extensionsList->firstItem();
4214 TQListBoxItem *nextItem;
4218 nextItem = item->next();
4220 if ( item->isSelected() )
4222 availableExtensionsList->insertItem( item->text() );
4223 extensionsList->removeItem( extensionsList->index( item ) );
4229 availableExtensionsList->sort();
4235 #include "kpropertiesdialog.moc"