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 <tdeapplication.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>
99 #include <tdelocale.h>
100 #include <tdeglobal.h>
101 #include <tdeglobalsettings.h>
102 #include <kstandarddirs.h>
103 #include <tdeio/job.h>
104 #include <tdeio/chmodjob.h>
105 #include <tdeio/renamedlg.h>
106 #include <tdeio/netaccess.h>
107 #include <tdeio/kservicetypefactory.h>
108 #include <tdefiledialog.h>
109 #include <kmimetype.h>
110 #include <kmountpoint.h>
111 #include <kiconloader.h>
112 #include <tdemessagebox.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 <tdeparts/componentfactory.h>
121 #include <kmetaprops.h>
122 #include <kpreviewprops.h>
123 #include <kprocess.h>
125 #include <tdelistview.h>
127 #include "tdefilesharedlg.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 = TDEIO::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(TDEIO::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(TDEIO::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(TDEIO::decodeFileName(_url.fileName())),
233 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
234 parent, name, modal),
237 d =
new KPropertiesDialogPrivate;
239 TDEIO::UDSEntry entry;
241 TDEIO::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(TDEIO::decodeFileName(_url.fileName())),
253 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
254 parent, name, modal),
257 d =
new KPropertiesDialogPrivate;
259 TDEIO::UDSEntry entry;
261 TDEIO::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(TDEIO::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( TDEIO::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->authorizeTDEAction(
"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-TDE-Protocol]) or "
522 " ([X-TDE-Protocol] == '%1' ) )" ).arg(item->url().protocol());
524 kdDebug( 250 ) <<
"trader query: " << query << endl;
525 TDETrader::OfferList offers = TDETrader::self()->query( mimetype, query );
526 TDETrader::OfferList::ConstIterator it = offers.begin();
527 TDETrader::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 TDEIO::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 =
"application-vnd.tde.tdemultiple";
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( TDEIcon::Desktop, TDEIcon::Device );
885 iconButton->
setIconType( TDEIcon::Desktop, TDEIcon::Application );
889 iconButton->
setIconType( TDEIcon::Desktop, TDEIcon::Place );
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( TDEGlobal::iconLoader()->loadIcon( item->iconName(), TDEIcon::Desktop, 48) );
905 iconLabel->setPixmap( TDEGlobal::iconLoader()->loadIcon( iconStr, TDEIcon::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( TDEIO::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->authorizeTDEAction(
"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(TDEIO::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(TDEIO::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(TDEGlobal::locale()->formatDateTime(dt), d->m_frame );
1063 grid->addWidget(l, curRow++, 2);
1066 tim = item->time(TDEIO::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(TDEGlobal::locale()->formatDateTime(dt), d->m_frame );
1074 grid->addWidget(l, curRow++, 2);
1077 tim = item->time(TDEIO::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(TDEGlobal::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 = TDEIO::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 +
" " + TDEProcess::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 =TDEGlobal::dirs()->relativeLocation(
"mime", path);
1184 if (m_sRelativePath.startsWith(
"/"))
1185 m_sRelativePath = TQString::null;
1189 m_sRelativePath =TDEGlobal::dirs()->relativeLocation(
"apps", path);
1190 if (m_sRelativePath.startsWith(
"/"))
1192 m_sRelativePath =TDEGlobal::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(TDEIO::convertSizeFromKB(kBAvail))
1215 .arg(TDEIO::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(TDEIO::convertSizeFromKB(kBAvail))
1230 .arg(TDEIO::convertSizeFromKB(kBSize))
1231 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
1234 void KFilePropsPlugin::slotDirSizeUpdate()
1236 TDEIO::filesize_t totalSize = d->dirSizeJob->totalSize();
1237 TDEIO::filesize_t totalFiles = d->dirSizeJob->totalFiles();
1238 TDEIO::filesize_t totalSubdirs = d->dirSizeJob->totalSubdirs();
1239 m_sizeLabel->setText( i18n(
"Calculating... %1 (%2)\n%3, %4")
1240 .arg(TDEIO::convertSize(totalSize))
1241 .arg(TDEGlobal::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( TDEIO::Job * job )
1249 m_sizeLabel->setText( job->errorString() );
1252 TDEIO::filesize_t totalSize =
static_cast<KDirSize*
>(job)->totalSize();
1253 TDEIO::filesize_t totalFiles =
static_cast<KDirSize*
>(job)->totalFiles();
1254 TDEIO::filesize_t totalSubdirs =
static_cast<KDirSize*
>(job)->totalSubdirs();
1255 m_sizeLabel->setText( TQString::fromLatin1(
"%1 (%2)\n%3, %4")
1256 .arg(TDEIO::convertSize(totalSize))
1257 .arg(TDEGlobal::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( TDEIO::Job * ) ),
1281 TQT_SLOT( slotDirSizeFinished( TDEIO::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 = TDEIO::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 tqt_enter_modal( TQWidget *widget );
1329 void tqt_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 TDEIO::Job * job = 0L;
1359 TQString newFileName = TDEIO::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( TDEIO::Job * ) ),
1383 TQT_SLOT( slotCopyFinished( TDEIO::Job * ) ) );
1384 connect( job, TQT_SIGNAL( renamed( TDEIO::Job *,
const KURL &,
const KURL & ) ),
1385 TQT_SLOT( slotFileRenamed( TDEIO::Job *,
const KURL &,
const KURL & ) ) );
1387 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
1388 tqt_enter_modal(&dummy);
1389 tqApp->enter_loop();
1390 tqt_leave_modal(&dummy);
1395 if ( !m_sRelativePath.isEmpty() ) {
1401 slotCopyFinished( 0L );
1404 void KFilePropsPlugin::slotCopyFinished( TDEIO::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 = TDEIO::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( TDEIO::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 TDECompletion *kcom = usrEdit->completionObject();
1775 kcom->setOrder(TDECompletion::Sorted);
1777 for (i=0; ((user = getpwent()) != 0L) && (i < maxEntries); i++)
1778 kcom->addItem(TQString::fromLatin1(user->pw_name));
1780 usrEdit->setCompletionMode((i < maxEntries) ? TDEGlobalSettings::CompletionAuto :
1781 TDEGlobalSettings::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 TDECompletion *kcom =
new TDECompletion;
1860 kcom->setItems(groupList);
1861 grpEdit->setCompletionObject(kcom,
true);
1862 grpEdit->setAutoDeleteCompletionObject(
true );
1863 grpEdit->setCompletionMode(TDEGlobalSettings::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 = TDEIO::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( TDEIO::Job * ) ),
2554 TQT_SLOT( slotChmodResult( TDEIO::Job * ) ) );
2556 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
2557 tqt_enter_modal(&dummy);
2558 tqApp->enter_loop();
2559 tqt_leave_modal(&dummy);
2561 if (dirs.count() > 0) {
2562 job = TDEIO::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( TDEIO::Job * ) ),
2570 TQT_SLOT( slotChmodResult( TDEIO::Job * ) ) );
2572 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
2573 tqt_enter_modal(&dummy);
2574 tqApp->enter_loop();
2575 tqt_leave_modal(&dummy);
2579 void KFilePermissionsPropsPlugin::slotChmodResult( TDEIO::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() ==
"media/builtin-mydocuments") {
2634 URLStr = TQString::null;
2635 TDEConfig xdguserconfig( TQDir::homeDirPath()+
"/.config/user-dirs.dirs" );
2636 URLEdit->
setMode(KFile::Directory);
2637 URLEdit->
setURL( xdguserconfig.readPathEntry(
"XDG_DOCUMENTS_DIR", TQDir::homeDirPath() +
"/Documents").remove(
"\"" ));
2639 else if (item && item->mimetype().startsWith(
"media/builtin-")) {
2640 URLEdit->setEnabled(
false);
2643 if ( !URLStr.isNull() ) {
2644 URLEdit->
setURL( URLStr );
2647 connect( URLEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2648 this, TQT_SIGNAL(
changed() ) );
2650 layout->addStretch (1);
2653 KURLPropsPlugin::~KURLPropsPlugin()
2663 bool KURLPropsPlugin::supports( KFileItemList _items )
2665 if ( _items.count() != 1 )
2667 KFileItem * item = _items.first();
2673 KDesktopFile config( item->url().path(),
true );
2674 return config.hasLinkType();
2682 if (item && item->mimetype() ==
"media/builtin-mydocuments") {
2683 TDEConfig xdgconfig(TQDir::homeDirPath()+
"/.config/user-dirs.dirs" );
2684 if (xdgconfig.isReadOnly()) {
2685 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2686 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2690 xdgconfig.writePathEntry(
"XDG_DOCUMENTS_DIR",
'"'+ URLEdit->
url() +
'"',
true,
false,
false, false );
2695 else if (item && item->mimetype().startsWith(
"media/builtin-")) {
2700 if ( !f.open( IO_ReadWrite ) ) {
2701 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2702 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2707 KSimpleConfig config( path );
2708 config.setDesktopGroup();
2709 config.writeEntry(
"Type", TQString::fromLatin1(
"Link"));
2710 config.writePathEntry(
"URL", URLEdit->
url() );
2713 if ( config.hasKey(
"Name") )
2715 TQString nameStr = nameFromFileName(
properties->
kurl().fileName());
2716 config.writeEntry(
"Name", nameStr );
2717 config.writeEntry(
"Name", nameStr,
true,
false,
true );
2729 class KBindingPropsPlugin::KBindingPropsPluginPrivate
2732 KBindingPropsPluginPrivate()
2735 ~KBindingPropsPluginPrivate()
2744 d =
new KBindingPropsPluginPrivate;
2745 d->m_frame =
properties->addPage(i18n(
"A&ssociation"));
2746 patternEdit =
new KLineEdit( d->m_frame,
"LineEdit_1" );
2747 commentEdit =
new KLineEdit( d->m_frame,
"LineEdit_2" );
2748 mimeEdit =
new KLineEdit( d->m_frame,
"LineEdit_3" );
2750 TQBoxLayout *mainlayout =
new TQVBoxLayout(d->m_frame, 0, KDialog::spacingHint());
2753 tmpQLabel =
new TQLabel( d->m_frame,
"Label_1" );
2754 tmpQLabel->setText( i18n(
"Pattern ( example: *.html;*.htm )") );
2755 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2756 mainlayout->addWidget(tmpQLabel, 1);
2760 patternEdit->setMaxLength( 512 );
2761 patternEdit->setMinimumSize( patternEdit->sizeHint() );
2762 patternEdit->setFixedHeight( fontHeight );
2763 mainlayout->addWidget(patternEdit, 1);
2765 tmpQLabel =
new TQLabel( d->m_frame,
"Label_2" );
2766 tmpQLabel->setText( i18n(
"Mime Type") );
2767 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2768 mainlayout->addWidget(tmpQLabel, 1);
2771 mimeEdit->setMaxLength( 256 );
2772 mimeEdit->setMinimumSize( mimeEdit->sizeHint() );
2773 mimeEdit->setFixedHeight( fontHeight );
2774 mainlayout->addWidget(mimeEdit, 1);
2776 tmpQLabel =
new TQLabel( d->m_frame,
"Label_3" );
2777 tmpQLabel->setText( i18n(
"Comment") );
2778 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2779 mainlayout->addWidget(tmpQLabel, 1);
2782 commentEdit->setMaxLength( 256 );
2783 commentEdit->setMinimumSize( commentEdit->sizeHint() );
2784 commentEdit->setFixedHeight( fontHeight );
2785 mainlayout->addWidget(commentEdit, 1);
2787 cbAutoEmbed =
new TQCheckBox( i18n(
"Left click previews"), d->m_frame,
"cbAutoEmbed" );
2788 mainlayout->addWidget(cbAutoEmbed, 1);
2790 mainlayout->addStretch (10);
2791 mainlayout->activate();
2793 TQFile f( _props->
kurl().path() );
2794 if ( !f.open( IO_ReadOnly ) )
2798 KSimpleConfig config( _props->
kurl().path() );
2799 config.setDesktopGroup();
2800 TQString patternStr = config.readEntry(
"Patterns" );
2801 TQString iconStr = config.readEntry(
"Icon" );
2802 TQString commentStr = config.readEntry(
"Comment" );
2803 m_sMimeStr = config.readEntry(
"MimeType" );
2805 if ( !patternStr.isEmpty() )
2806 patternEdit->setText( patternStr );
2807 if ( !commentStr.isEmpty() )
2808 commentEdit->setText( commentStr );
2809 if ( !m_sMimeStr.isEmpty() )
2810 mimeEdit->setText( m_sMimeStr );
2811 cbAutoEmbed->setTristate();
2812 if ( config.hasKey(
"X-TDE-AutoEmbed" ) )
2813 cbAutoEmbed->setChecked( config.readBoolEntry(
"X-TDE-AutoEmbed" ) );
2815 cbAutoEmbed->setNoChange();
2817 connect( patternEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2818 this, TQT_SIGNAL(
changed() ) );
2819 connect( commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2820 this, TQT_SIGNAL(
changed() ) );
2821 connect( mimeEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2822 this, TQT_SIGNAL(
changed() ) );
2823 connect( cbAutoEmbed, TQT_SIGNAL( toggled(
bool ) ),
2824 this, TQT_SIGNAL(
changed() ) );
2827 KBindingPropsPlugin::~KBindingPropsPlugin()
2837 bool KBindingPropsPlugin::supports( KFileItemList _items )
2839 if ( _items.count() != 1 )
2841 KFileItem * item = _items.first();
2847 KDesktopFile config( item->url().path(),
true );
2848 return config.hasMimeTypeType();
2856 if ( !f.open( IO_ReadWrite ) )
2858 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2859 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2864 KSimpleConfig config( path );
2865 config.setDesktopGroup();
2866 config.writeEntry(
"Type", TQString::fromLatin1(
"MimeType") );
2868 config.writeEntry(
"Patterns", patternEdit->text() );
2869 config.writeEntry(
"Comment", commentEdit->text() );
2870 config.writeEntry(
"Comment",
2871 commentEdit->text(),
true,
false, true );
2872 config.writeEntry(
"MimeType", mimeEdit->text() );
2873 if ( cbAutoEmbed->state() == TQButton::NoChange )
2874 config.deleteEntry(
"X-TDE-AutoEmbed",
false );
2876 config.writeEntry(
"X-TDE-AutoEmbed", cbAutoEmbed->isChecked() );
2886 class KDevicePropsPlugin::KDevicePropsPluginPrivate
2889 KDevicePropsPluginPrivate()
2892 ~KDevicePropsPluginPrivate()
2897 TQStringList mountpointlist;
2898 TQLabel *m_freeSpaceText;
2899 TQLabel *m_freeSpaceLabel;
2900 TQProgressBar *m_freeSpaceBar;
2905 d =
new KDevicePropsPluginPrivate;
2906 d->m_frame =
properties->addPage(i18n(
"De&vice"));
2908 TQStringList devices;
2909 KMountPoint::List mountPoints = KMountPoint::possibleMountPoints();
2911 for(KMountPoint::List::ConstIterator it = mountPoints.begin();
2912 it != mountPoints.end(); ++it)
2914 KMountPoint *mp = *it;
2915 TQString mountPoint = mp->mountPoint();
2916 TQString device = mp->mountedFrom();
2917 kdDebug()<<
"mountPoint :"<<mountPoint<<
" device :"<<device<<
" mp->mountType() :"<<mp->mountType()<<endl;
2919 if ((mountPoint !=
"-") && (mountPoint !=
"none") && !mountPoint.isEmpty()
2920 && device !=
"none")
2922 devices.append( device + TQString::fromLatin1(
" (")
2923 + mountPoint + TQString::fromLatin1(
")") );
2924 m_devicelist.append(device);
2925 d->mountpointlist.append(mountPoint);
2929 TQGridLayout *layout =
new TQGridLayout( d->m_frame, 0, 2, 0,
2930 KDialog::spacingHint());
2931 layout->setColStretch(1, 1);
2934 label =
new TQLabel( d->m_frame );
2935 label->setText( devices.count() == 0 ?
2936 i18n(
"Device (/dev/fd0):") :
2938 layout->addWidget(label, 0, 0);
2940 device =
new TQComboBox(
true, d->m_frame,
"ComboBox_device" );
2941 device->insertStringList( devices );
2942 layout->addWidget(device, 0, 1);
2943 connect( device, TQT_SIGNAL( activated(
int ) ),
2944 this, TQT_SLOT( slotActivated(
int ) ) );
2946 readonly =
new TQCheckBox( d->m_frame,
"CheckBox_readonly" );
2947 readonly->setText( i18n(
"Read only") );
2948 layout->addWidget(readonly, 1, 1);
2950 label =
new TQLabel( d->m_frame );
2951 label->setText( i18n(
"File system:") );
2952 layout->addWidget(label, 2, 0);
2954 TQLabel *fileSystem =
new TQLabel( d->m_frame );
2955 layout->addWidget(fileSystem, 2, 1);
2957 label =
new TQLabel( d->m_frame );
2958 label->setText( devices.count()==0 ?
2959 i18n(
"Mount point (/mnt/floppy):") :
2960 i18n(
"Mount point:"));
2961 layout->addWidget(label, 3, 0);
2963 mountpoint =
new TQLabel( d->m_frame,
"LineEdit_mountpoint" );
2965 layout->addWidget(mountpoint, 3, 1);
2968 d->m_freeSpaceText =
new TQLabel(i18n(
"Free disk space:"), d->m_frame );
2969 layout->addWidget(d->m_freeSpaceText, 4, 0);
2971 d->m_freeSpaceLabel =
new TQLabel( d->m_frame );
2972 layout->addWidget( d->m_freeSpaceLabel, 4, 1 );
2974 d->m_freeSpaceBar =
new TQProgressBar( d->m_frame,
"freeSpaceBar" );
2975 layout->addMultiCellWidget(d->m_freeSpaceBar, 5, 5, 0, 1);
2978 d->m_freeSpaceText->hide();
2979 d->m_freeSpaceLabel->hide();
2980 d->m_freeSpaceBar->hide();
2982 KSeparator* sep =
new KSeparator( KSeparator::HLine, d->m_frame);
2983 layout->addMultiCellWidget(sep, 6, 6, 0, 1);
2986 int bsize = 66 + 2 * unmounted->style().pixelMetric(TQStyle::PM_ButtonMargin);
2987 unmounted->setFixedSize(bsize, bsize);
2988 unmounted->setIconType(TDEIcon::Desktop, TDEIcon::Device);
2989 layout->addWidget(unmounted, 7, 0);
2991 label =
new TQLabel( i18n(
"Unmounted Icon"), d->m_frame );
2992 layout->addWidget(label, 7, 1);
2994 layout->setRowStretch(8, 1);
2996 TQString path( _props->
kurl().path() );
2999 if ( !f.open( IO_ReadOnly ) )
3003 KSimpleConfig config( path );
3004 config.setDesktopGroup();
3005 TQString deviceStr = config.readEntry(
"Dev" );
3006 TQString mountPointStr = config.readEntry(
"MountPoint" );
3007 bool ro = config.readBoolEntry(
"ReadOnly",
false );
3008 TQString unmountedStr = config.readEntry(
"UnmountIcon" );
3010 TQString fsType = config.readEntry(
"FSType");
3011 fileSystem->setText( (fsType.stripWhiteSpace() !=
"") ? i18n(fsType.local8Bit()) :
"" );
3013 device->setEditText( deviceStr );
3014 if ( !deviceStr.isEmpty() ) {
3016 int index = m_devicelist.findIndex(deviceStr);
3020 slotActivated( index );
3024 if ( !mountPointStr.isEmpty() )
3026 mountpoint->setText( mountPointStr );
3030 readonly->setChecked( ro );
3032 if ( unmountedStr.isEmpty() )
3033 unmountedStr = KMimeType::defaultMimeTypePtr()->KServiceType::icon();
3035 unmounted->setIcon( unmountedStr );
3037 connect( device, TQT_SIGNAL( activated(
int ) ),
3038 this, TQT_SIGNAL(
changed() ) );
3039 connect( device, TQT_SIGNAL( textChanged(
const TQString & ) ),
3040 this, TQT_SIGNAL(
changed() ) );
3041 connect( readonly, TQT_SIGNAL( toggled(
bool ) ),
3042 this, TQT_SIGNAL(
changed() ) );
3043 connect( unmounted, TQT_SIGNAL( iconChanged( TQString ) ),
3044 this, TQT_SIGNAL(
changed() ) );
3046 connect( device, TQT_SIGNAL( textChanged(
const TQString & ) ),
3047 this, TQT_SLOT( slotDeviceChanged() ) );
3052 KDevicePropsPlugin::~KDevicePropsPlugin()
3062 void KDevicePropsPlugin::processLockouts()
3064 if (device->currentText().stripWhiteSpace() !=
"")
3074 void KDevicePropsPlugin::updateInfo()
3077 d->m_freeSpaceText->hide();
3078 d->m_freeSpaceLabel->hide();
3079 d->m_freeSpaceBar->hide();
3081 if ( !mountpoint->text().isEmpty() )
3084 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
3085 const unsigned long&,
const TQString& ) ),
3086 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
3087 const unsigned long&,
const TQString& ) ) );
3089 job->
readDF( mountpoint->text() );
3095 void KDevicePropsPlugin::slotActivated(
int index )
3098 device->setEditText( m_devicelist[index] );
3099 mountpoint->setText( d->mountpointlist[index] );
3104 void KDevicePropsPlugin::slotDeviceChanged()
3107 int index = m_devicelist.findIndex( device->currentText() );
3109 mountpoint->setText( d->mountpointlist[index] );
3111 mountpoint->setText( TQString::null );
3116 void KDevicePropsPlugin::slotFoundMountPoint(
const unsigned long& kBSize,
3117 const unsigned long& ,
3118 const unsigned long& kBAvail,
3121 d->m_freeSpaceText->show();
3122 d->m_freeSpaceLabel->show();
3124 int percUsed = 100 - (int)(100.0 * kBAvail / kBSize);
3126 d->m_freeSpaceLabel->setText(
3128 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
3129 .arg(TDEIO::convertSizeFromKB(kBAvail))
3130 .arg(TDEIO::convertSizeFromKB(kBSize))
3131 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
3133 d->m_freeSpaceBar->setProgress(percUsed, 100);
3134 d->m_freeSpaceBar->show();
3137 bool KDevicePropsPlugin::supports( KFileItemList _items )
3139 if ( _items.count() != 1 )
3141 KFileItem * item = _items.first();
3146 KDesktopFile config( item->url().path(),
true );
3147 return config.hasDeviceType();
3154 if ( !f.open( IO_ReadWrite ) )
3156 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have sufficient "
3157 "access to write to <b>%1</b>.</qt>").arg(path));
3162 KSimpleConfig config( path );
3163 config.setDesktopGroup();
3164 config.writeEntry(
"Type", TQString::fromLatin1(
"FSDevice") );
3166 config.writeEntry(
"Dev", device->currentText() );
3167 config.writeEntry(
"MountPoint", mountpoint->text() );
3169 config.writeEntry(
"UnmountIcon", unmounted->
icon() );
3170 kdDebug(250) <<
"unmounted->icon() = " << unmounted->
icon() << endl;
3172 config.writeEntry(
"ReadOnly", readonly->isChecked() );
3188 TQFrame *frame =
properties->addPage(i18n(
"&Application"));
3189 TQVBoxLayout *mainlayout =
new TQVBoxLayout( frame, 0, KDialog::spacingHint() );
3191 w =
new KPropertiesDesktopBase(frame);
3192 mainlayout->addWidget(w);
3194 bool bKDesktopMode = (TQCString(tqApp->name()) ==
"kdesktop");
3199 w->nameEdit->hide();
3200 w->nameLabel->hide();
3203 w->pathEdit->setMode(KFile::Directory | KFile::LocalOnly);
3204 w->pathEdit->lineEdit()->setAcceptDrops(
false);
3206 connect( w->nameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3207 connect( w->genNameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3208 connect( w->commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3209 connect( w->commandEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3210 connect( w->pathEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3212 connect( w->browseButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotBrowseExec() ) );
3213 connect( w->addFiletypeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotAddFiletype() ) );
3214 connect( w->delFiletypeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotDelFiletype() ) );
3215 connect( w->advancedButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotAdvanced() ) );
3218 TQString path = _props->
kurl().path();
3220 if ( !f.open( IO_ReadOnly ) )
3224 KDesktopFile config( path );
3225 TQString nameStr = config.readName();
3226 TQString genNameStr = config.readGenericName();
3227 TQString commentStr = config.readComment();
3228 TQString commandStr = config.readPathEntry(
"Exec" );
3229 if (commandStr.left(12) ==
"ksystraycmd ")
3231 commandStr.remove(0, 12);
3232 m_systrayBool =
true;
3235 m_systrayBool =
false;
3237 m_origCommandStr = commandStr;
3238 TQString pathStr = config.readPathEntry(
"Path" );
3239 m_terminalBool = config.readBoolEntry(
"Terminal" );
3240 m_terminalOptionStr = config.readEntry(
"TerminalOptions" );
3241 m_suidBool = config.readBoolEntry(
"X-TDE-SubstituteUID" ) || config.readBoolEntry(
"X-KDE-SubstituteUID" );
3242 if( config.hasKey(
"X-TDE-Username" ))
3243 m_suidUserStr = config.readEntry(
"X-TDE-Username" );
3245 m_suidUserStr = config.readEntry(
"X-KDE-Username" );
3246 if( config.hasKey(
"StartupNotify" ))
3247 m_startupBool = config.readBoolEntry(
"StartupNotify",
true );
3249 m_startupBool = config.readBoolEntry(
"X-TDE-StartupNotify",
true );
3250 m_dcopServiceType = config.readEntry(
"X-DCOP-ServiceType").lower();
3252 TQStringList mimeTypes = config.readListEntry(
"MimeType",
';' );
3254 if ( nameStr.isEmpty() || bKDesktopMode ) {
3260 if ( !bKDesktopMode )
3261 w->nameEdit->setText(nameStr);
3263 w->genNameEdit->setText( genNameStr );
3264 w->commentEdit->setText( commentStr );
3265 w->commandEdit->setText( commandStr );
3266 w->pathEdit->lineEdit()->setText( pathStr );
3267 w->filetypeList->setAllColumnsShowFocus(
true);
3269 KMimeType::Ptr defaultMimetype = KMimeType::defaultMimeTypePtr();
3270 for(TQStringList::ConstIterator it = mimeTypes.begin();
3271 it != mimeTypes.end(); )
3273 KMimeType::Ptr p = KMimeType::mimeType(*it);
3275 TQString preference;
3276 if (it != mimeTypes.end())
3279 (*it).toInt(&numeric);
3286 if (p && (p != defaultMimetype))
3288 new TQListViewItem(w->filetypeList, p->name(), p->comment(), preference);
3294 KDesktopPropsPlugin::~KDesktopPropsPlugin()
3298 void KDesktopPropsPlugin::slotSelectMimetype()
3300 TQListView *w = (TQListView*)sender();
3301 TQListViewItem *item = w->firstChild();
3304 if (item->isSelected())
3305 w->setSelected(item,
false);
3306 item = item->nextSibling();
3310 void KDesktopPropsPlugin::slotAddFiletype()
3312 KDialogBase dlg(w,
"KPropertiesMimetypes",
true,
3314 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
3316 KGuiItem okItem(i18n(
"&Add"), TQString::null ,
3317 i18n(
"Add the selected file types to\nthe list of supported file types."),
3318 i18n(
"Add the selected file types to\nthe list of supported file types."));
3319 dlg.setButtonOK(okItem);
3321 KPropertiesMimetypeBase *mw =
new KPropertiesMimetypeBase(&dlg);
3323 dlg.setMainWidget(mw);
3326 mw->listView->setRootIsDecorated(
true);
3327 mw->listView->setSelectionMode(TQListView::Extended);
3328 mw->listView->setAllColumnsShowFocus(
true);
3329 mw->listView->setFullWidth(
true);
3330 mw->listView->setMinimumSize(500,400);
3332 connect(mw->listView, TQT_SIGNAL(selectionChanged()),
3333 this, TQT_SLOT(slotSelectMimetype()));
3334 connect(mw->listView, TQT_SIGNAL(doubleClicked( TQListViewItem *,
const TQPoint &,
int )),
3335 &dlg, TQT_SLOT( slotOk()));
3337 TQMap<TQString,TQListViewItem*> majorMap;
3338 TQListViewItem *majorGroup;
3339 KMimeType::List mimetypes = KMimeType::allMimeTypes();
3340 TQValueListIterator<KMimeType::Ptr> it(mimetypes.begin());
3341 for (; it != mimetypes.end(); ++it) {
3342 TQString mimetype = (*it)->name();
3343 if (mimetype == KMimeType::defaultMimeType())
3345 int index = mimetype.find(
"/");
3346 TQString maj = mimetype.left(index);
3347 TQString min = mimetype.mid(index+1);
3349 TQMapIterator<TQString,TQListViewItem*> mit = majorMap.find( maj );
3350 if ( mit == majorMap.end() ) {
3351 majorGroup =
new TQListViewItem( mw->listView, maj );
3352 majorGroup->setExpandable(
true);
3353 mw->listView->setOpen(majorGroup,
true);
3354 majorMap.insert( maj, majorGroup );
3358 majorGroup = mit.data();
3361 TQListViewItem *item =
new TQListViewItem(majorGroup, min, (*it)->comment());
3362 item->setPixmap(0, (*it)->pixmap(TDEIcon::Small, IconSize(TDEIcon::Small)));
3364 TQMapIterator<TQString,TQListViewItem*> mit = majorMap.find(
"all" );
3365 if ( mit != majorMap.end())
3367 mw->listView->setCurrentItem(mit.data());
3368 mw->listView->ensureItemVisible(mit.data());
3372 if (dlg.exec() == KDialogBase::Accepted)
3374 KMimeType::Ptr defaultMimetype = KMimeType::defaultMimeTypePtr();
3375 TQListViewItem *majorItem = mw->listView->firstChild();
3378 TQString major = majorItem->text(0);
3380 TQListViewItem *minorItem = majorItem->firstChild();
3383 if (minorItem->isSelected())
3385 TQString mimetype = major +
"/" + minorItem->text(0);
3386 KMimeType::Ptr p = KMimeType::mimeType(mimetype);
3387 if (p && (p != defaultMimetype))
3389 mimetype = p->name();
3391 TQListViewItem *item = w->filetypeList->firstChild();
3394 if (mimetype == item->text(0))
3399 item = item->nextSibling();
3402 new TQListViewItem(w->filetypeList, p->name(), p->comment());
3407 minorItem = minorItem->nextSibling();
3410 majorItem = majorItem->nextSibling();
3416 void KDesktopPropsPlugin::slotDelFiletype()
3418 delete w->filetypeList->currentItem();
3422 void KDesktopPropsPlugin::checkCommandChanged()
3424 if (KRun::binaryName(w->commandEdit->text(),
true) !=
3425 KRun::binaryName(m_origCommandStr,
true))
3427 TQString m_origCommandStr = w->commandEdit->text();
3428 m_dcopServiceType= TQString::null;
3434 kdDebug(250) <<
"KDesktopPropsPlugin::applyChanges" << endl;
3439 if ( !f.open( IO_ReadWrite ) ) {
3440 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
3441 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
3448 checkCommandChanged();
3450 KSimpleConfig config( path );
3451 config.setDesktopGroup();
3452 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
3453 config.writeEntry(
"Comment", w->commentEdit->text() );
3454 config.writeEntry(
"Comment", w->commentEdit->text(),
true,
false, true );
3455 config.writeEntry(
"GenericName", w->genNameEdit->text() );
3456 config.writeEntry(
"GenericName", w->genNameEdit->text(),
true,
false, true );
3459 config.writePathEntry(
"Exec", w->commandEdit->text().prepend(
"ksystraycmd ") );
3461 config.writePathEntry(
"Exec", w->commandEdit->text() );
3462 config.writePathEntry(
"Path", w->pathEdit->lineEdit()->text() );
3465 TQStringList mimeTypes;
3466 for( TQListViewItem *item = w->filetypeList->firstChild();
3467 item; item = item->nextSibling() )
3469 TQString preference = item->text(2);
3470 mimeTypes.append(item->text(0));
3471 if (!preference.isEmpty())
3472 mimeTypes.append(preference);
3475 config.writeEntry(
"MimeType", mimeTypes,
';' );
3477 if ( !w->nameEdit->isHidden() ) {
3478 TQString nameStr = w->nameEdit->text();
3479 config.writeEntry(
"Name", nameStr );
3480 config.writeEntry(
"Name", nameStr,
true,
false,
true );
3483 config.writeEntry(
"Terminal", m_terminalBool);
3484 config.writeEntry(
"TerminalOptions", m_terminalOptionStr);
3485 config.writeEntry(
"X-TDE-SubstituteUID", m_suidBool);
3486 config.writeEntry(
"X-TDE-Username", m_suidUserStr);
3487 config.writeEntry(
"StartupNotify", m_startupBool);
3488 config.writeEntry(
"X-DCOP-ServiceType", m_dcopServiceType);
3492 TQString sycocaPath = TDEGlobal::dirs()->relativeLocation(
"apps", path);
3493 bool updateNeeded = !sycocaPath.startsWith(
"/");
3496 sycocaPath = TDEGlobal::dirs()->relativeLocation(
"xdgdata-apps", path);
3497 updateNeeded = !sycocaPath.startsWith(
"/");
3500 KService::rebuildKSycoca(w);
3504 void KDesktopPropsPlugin::slotBrowseExec()
3507 TQString::null, w );
3511 if ( !f.isLocalFile()) {
3512 KMessageBox::sorry(w, i18n(
"Only executables on local file systems are supported."));
3516 TQString path = f.path();
3517 KRun::shellQuote( path );
3518 w->commandEdit->setText( path );
3521 void KDesktopPropsPlugin::slotAdvanced()
3523 KDialogBase dlg(w,
"KPropertiesDesktopAdv",
true,
3524 i18n(
"Advanced Options for %1").arg(
properties->
kurl().fileName()),
3525 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
3526 KPropertiesDesktopAdvBase *w =
new KPropertiesDesktopAdvBase(&dlg);
3528 dlg.setMainWidget(w);
3532 checkCommandChanged();
3536 TDEConfigGroup confGroup( TDEGlobal::config(), TQString::fromLatin1(
"General") );
3537 TQString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication",
3538 TQString::fromLatin1(
"konsole"));
3540 bool terminalCloseBool =
false;
3542 if (preferredTerminal ==
"konsole")
3544 terminalCloseBool = (m_terminalOptionStr.contains(
"--noclose" ) > 0);
3545 w->terminalCloseCheck->setChecked(terminalCloseBool);
3546 m_terminalOptionStr.replace(
"--noclose",
"");
3550 w->terminalCloseCheck->hide();
3553 w->terminalCheck->setChecked(m_terminalBool);
3554 w->terminalEdit->setText(m_terminalOptionStr);
3555 w->terminalCloseCheck->setEnabled(m_terminalBool);
3556 w->terminalEdit->setEnabled(m_terminalBool);
3557 w->terminalEditLabel->setEnabled(m_terminalBool);
3559 w->suidCheck->setChecked(m_suidBool);
3560 w->suidEdit->setText(m_suidUserStr);
3561 w->suidEdit->setEnabled(m_suidBool);
3562 w->suidEditLabel->setEnabled(m_suidBool);
3564 w->startupInfoCheck->setChecked(m_startupBool);
3565 w->systrayCheck->setChecked(m_systrayBool);
3567 if (m_dcopServiceType ==
"unique")
3568 w->dcopCombo->setCurrentItem(2);
3569 else if (m_dcopServiceType ==
"multi")
3570 w->dcopCombo->setCurrentItem(1);
3571 else if (m_dcopServiceType ==
"wait")
3572 w->dcopCombo->setCurrentItem(3);
3574 w->dcopCombo->setCurrentItem(0);
3577 TDECompletion *kcom =
new TDECompletion;
3578 kcom->setOrder(TDECompletion::Sorted);
3580 int i, maxEntries = 1000;
3582 for (i=0; ((pw = getpwent()) != 0L) && (i < maxEntries); i++)
3583 kcom->addItem(TQString::fromLatin1(pw->pw_name));
3587 w->suidEdit->setCompletionObject(kcom,
true);
3588 w->suidEdit->setAutoDeleteCompletionObject(
true );
3589 w->suidEdit->setCompletionMode(TDEGlobalSettings::CompletionAuto);
3596 connect( w->terminalEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3597 this, TQT_SIGNAL(
changed() ) );
3598 connect( w->terminalCloseCheck, TQT_SIGNAL( toggled(
bool ) ),
3599 this, TQT_SIGNAL(
changed() ) );
3600 connect( w->terminalCheck, TQT_SIGNAL( toggled(
bool ) ),
3601 this, TQT_SIGNAL(
changed() ) );
3602 connect( w->suidCheck, TQT_SIGNAL( toggled(
bool ) ),
3603 this, TQT_SIGNAL(
changed() ) );
3604 connect( w->suidEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3605 this, TQT_SIGNAL(
changed() ) );
3606 connect( w->startupInfoCheck, TQT_SIGNAL( toggled(
bool ) ),
3607 this, TQT_SIGNAL(
changed() ) );
3608 connect( w->systrayCheck, TQT_SIGNAL( toggled(
bool ) ),
3609 this, TQT_SIGNAL(
changed() ) );
3610 connect( w->dcopCombo, TQT_SIGNAL( highlighted(
int ) ),
3611 this, TQT_SIGNAL(
changed() ) );
3613 if ( dlg.exec() == TQDialog::Accepted )
3615 m_terminalOptionStr = w->terminalEdit->text().stripWhiteSpace();
3616 m_terminalBool = w->terminalCheck->isChecked();
3617 m_suidBool = w->suidCheck->isChecked();
3618 m_suidUserStr = w->suidEdit->text().stripWhiteSpace();
3619 m_startupBool = w->startupInfoCheck->isChecked();
3620 m_systrayBool = w->systrayCheck->isChecked();
3622 if (w->terminalCloseCheck->isChecked())
3624 m_terminalOptionStr.append(
" --noclose");
3627 switch(w->dcopCombo->currentItem())
3629 case 1: m_dcopServiceType =
"multi";
break;
3630 case 2: m_dcopServiceType =
"unique";
break;
3631 case 3: m_dcopServiceType =
"wait";
break;
3632 default: m_dcopServiceType =
"none";
break;
3637 bool KDesktopPropsPlugin::supports( KFileItemList _items )
3639 if ( _items.count() != 1 )
3641 KFileItem * item = _items.first();
3646 KDesktopFile config( item->url().path(),
true );
3647 return config.hasApplicationType() && kapp->authorize(
"run_desktop_files") && kapp->authorize(
"shell_access");
3650 void KPropertiesDialog::virtual_hook(
int id,
void* data )
3651 { KDialogBase::virtual_hook(
id, data ); }
3653 void KPropsDlgPlugin::virtual_hook(
int,
void* )
3665 class KExecPropsPlugin::KExecPropsPluginPrivate
3668 KExecPropsPluginPrivate()
3671 ~KExecPropsPluginPrivate()
3676 TQCheckBox *nocloseonexitCheck;
3682 d =
new KExecPropsPluginPrivate;
3683 d->m_frame =
properties->addPage(i18n(
"E&xecute"));
3684 TQVBoxLayout * mainlayout =
new TQVBoxLayout( d->m_frame, 0,
3685 KDialog::spacingHint());
3690 l =
new TQLabel( i18n(
"Comman&d:" ), d->m_frame );
3691 mainlayout->addWidget(l);
3693 TQHBoxLayout * hlayout;
3694 hlayout =
new TQHBoxLayout(KDialog::spacingHint());
3695 mainlayout->addLayout(hlayout);
3697 execEdit =
new KLineEdit( d->m_frame );
3698 TQWhatsThis::add(execEdit,i18n(
3699 "Following the command, you can have several place holders which will be replaced "
3700 "with the actual values when the actual program is run:\n"
3701 "%f - a single file name\n"
3702 "%F - a list of files; use for applications that can open several local files at once\n"
3703 "%u - a single URL\n"
3704 "%U - a list of URLs\n"
3705 "%d - the folder of the file to open\n"
3706 "%D - a list of folders\n"
3708 "%m - the mini-icon\n"
3709 "%c - the caption"));
3710 hlayout->addWidget(execEdit, 1);
3712 l->setBuddy( execEdit );
3714 execBrowse =
new TQPushButton( d->m_frame );
3715 execBrowse->setText( i18n(
"&Browse...") );
3716 hlayout->addWidget(execBrowse);
3719 TQGroupBox* tmpQGroupBox;
3720 tmpQGroupBox =
new TQGroupBox( i18n(
"Panel Embedding"), d->m_frame );
3721 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3723 mainlayout->addWidget(tmpQGroupBox);
3725 TQGridLayout *grid =
new TQGridLayout(tmpQGroupBox->layout(), 2, 2);
3726 grid->setSpacing( KDialog::spacingHint() );
3727 grid->setColStretch(1, 1);
3729 l =
new TQLabel( i18n(
"&Execute on click:" ), tmpQGroupBox );
3730 grid->addWidget(l, 0, 0);
3732 swallowExecEdit =
new KLineEdit( tmpQGroupBox );
3733 grid->addWidget(swallowExecEdit, 0, 1);
3735 l->setBuddy( swallowExecEdit );
3737 l =
new TQLabel( i18n(
"&Window title:" ), tmpQGroupBox );
3738 grid->addWidget(l, 1, 0);
3740 swallowTitleEdit =
new KLineEdit( tmpQGroupBox );
3741 grid->addWidget(swallowTitleEdit, 1, 1);
3743 l->setBuddy( swallowTitleEdit );
3747 tmpQGroupBox =
new TQGroupBox( d->m_frame );
3748 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3750 mainlayout->addWidget(tmpQGroupBox);
3752 grid =
new TQGridLayout(tmpQGroupBox->layout(), 3, 2);
3753 grid->setSpacing( KDialog::spacingHint() );
3754 grid->setColStretch(1, 1);
3756 terminalCheck =
new TQCheckBox( tmpQGroupBox );
3757 terminalCheck->setText( i18n(
"&Run in terminal") );
3758 grid->addMultiCellWidget(terminalCheck, 0, 0, 0, 1);
3762 TDEConfigGroup confGroup( TDEGlobal::config(), TQString::fromLatin1(
"General") );
3763 TQString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication",
3764 TQString::fromLatin1(
"konsole"));
3767 d->nocloseonexitCheck = 0L;
3768 if (preferredTerminal ==
"konsole")
3771 d->nocloseonexitCheck =
new TQCheckBox( tmpQGroupBox );
3772 d->nocloseonexitCheck->setText( i18n(
"Do not &close when command exits") );
3773 grid->addMultiCellWidget(d->nocloseonexitCheck, 1, 1, 0, 1);
3776 terminalLabel =
new TQLabel( i18n(
"&Terminal options:" ), tmpQGroupBox );
3777 grid->addWidget(terminalLabel, posOptions, 0);
3779 terminalEdit =
new KLineEdit( tmpQGroupBox );
3780 grid->addWidget(terminalEdit, posOptions, 1);
3782 terminalLabel->setBuddy( terminalEdit );
3786 tmpQGroupBox =
new TQGroupBox( d->m_frame );
3787 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3789 mainlayout->addWidget(tmpQGroupBox);
3791 grid =
new TQGridLayout(tmpQGroupBox->layout(), 2, 2);
3792 grid->setSpacing(KDialog::spacingHint());
3793 grid->setColStretch(1, 1);
3795 suidCheck =
new TQCheckBox(tmpQGroupBox);
3796 suidCheck->setText(i18n(
"Ru&n as a different user"));
3797 grid->addMultiCellWidget(suidCheck, 0, 0, 0, 1);
3799 suidLabel =
new TQLabel(i18n(
"&Username:" ), tmpQGroupBox);
3800 grid->addWidget(suidLabel, 1, 0);
3802 suidEdit =
new KLineEdit(tmpQGroupBox);
3803 grid->addWidget(suidEdit, 1, 1);
3805 suidLabel->setBuddy( suidEdit );
3807 mainlayout->addStretch(1);
3810 TQString path = _props->
kurl().path();
3812 if ( !f.open( IO_ReadOnly ) )
3816 KSimpleConfig config( path );
3817 config.setDollarExpansion(
false );
3818 config.setDesktopGroup();
3819 execStr = config.readPathEntry(
"Exec" );
3820 swallowExecStr = config.readPathEntry(
"SwallowExec" );
3821 swallowTitleStr = config.readEntry(
"SwallowTitle" );
3822 termBool = config.readBoolEntry(
"Terminal" );
3823 termOptionsStr = config.readEntry(
"TerminalOptions" );
3824 suidBool = config.readBoolEntry(
"X-TDE-SubstituteUID" );
3825 suidUserStr = config.readEntry(
"X-TDE-Username" );
3827 if ( !swallowExecStr.isNull() )
3828 swallowExecEdit->setText( swallowExecStr );
3829 if ( !swallowTitleStr.isNull() )
3830 swallowTitleEdit->setText( swallowTitleStr );
3832 if ( !execStr.isNull() )
3833 execEdit->setText( execStr );
3835 if ( d->nocloseonexitCheck )
3837 d->nocloseonexitCheck->setChecked( (termOptionsStr.contains(
"--noclose" ) > 0) );
3838 termOptionsStr.replace(
"--noclose",
"");
3840 if ( !termOptionsStr.isNull() )
3841 terminalEdit->setText( termOptionsStr );
3843 terminalCheck->setChecked( termBool );
3844 enableCheckedEdit();
3846 suidCheck->setChecked( suidBool );
3847 suidEdit->setText( suidUserStr );
3851 TDECompletion *kcom =
new TDECompletion;
3852 kcom->setOrder(TDECompletion::Sorted);
3854 int i, maxEntries = 1000;
3856 for (i=0; ((pw = getpwent()) != 0L) && (i < maxEntries); i++)
3857 kcom->addItem(TQString::fromLatin1(pw->pw_name));
3861 suidEdit->setCompletionObject(kcom,
true);
3862 suidEdit->setAutoDeleteCompletionObject(
true );
3863 suidEdit->setCompletionMode(TDEGlobalSettings::CompletionAuto);
3870 connect( swallowExecEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3871 this, TQT_SIGNAL(
changed() ) );
3872 connect( swallowTitleEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3873 this, TQT_SIGNAL(
changed() ) );
3874 connect( execEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3875 this, TQT_SIGNAL(
changed() ) );
3876 connect( terminalEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3877 this, TQT_SIGNAL(
changed() ) );
3878 if (d->nocloseonexitCheck)
3879 connect( d->nocloseonexitCheck, TQT_SIGNAL( toggled(
bool ) ),
3880 this, TQT_SIGNAL(
changed() ) );
3881 connect( terminalCheck, TQT_SIGNAL( toggled(
bool ) ),
3882 this, TQT_SIGNAL(
changed() ) );
3883 connect( suidCheck, TQT_SIGNAL( toggled(
bool ) ),
3884 this, TQT_SIGNAL(
changed() ) );
3885 connect( suidEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3886 this, TQT_SIGNAL(
changed() ) );
3888 connect( execBrowse, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotBrowseExec() ) );
3889 connect( terminalCheck, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( enableCheckedEdit() ) );
3890 connect( suidCheck, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( enableSuidEdit() ) );
3894 KExecPropsPlugin::~KExecPropsPlugin()
3899 void KExecPropsPlugin::enableCheckedEdit()
3901 bool checked = terminalCheck->isChecked();
3902 terminalLabel->setEnabled( checked );
3903 if (d->nocloseonexitCheck)
3904 d->nocloseonexitCheck->setEnabled( checked );
3905 terminalEdit->setEnabled( checked );
3908 void KExecPropsPlugin::enableSuidEdit()
3910 bool checked = suidCheck->isChecked();
3911 suidLabel->setEnabled( checked );
3912 suidEdit->setEnabled( checked );
3915 bool KExecPropsPlugin::supports( KFileItemList _items )
3917 if ( _items.count() != 1 )
3919 KFileItem * item = _items.first();
3924 KDesktopFile config( item->url().path(),
true );
3925 return config.hasApplicationType() && kapp->authorize(
"run_desktop_files") && kapp->authorize(
"shell_access");
3930 kdDebug(250) <<
"KExecPropsPlugin::applyChanges" << endl;
3935 if ( !f.open( IO_ReadWrite ) ) {
3936 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
3937 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
3942 KSimpleConfig config( path );
3943 config.setDesktopGroup();
3944 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
3945 config.writePathEntry(
"Exec", execEdit->text() );
3946 config.writePathEntry(
"SwallowExec", swallowExecEdit->text() );
3947 config.writeEntry(
"SwallowTitle", swallowTitleEdit->text() );
3948 config.writeEntry(
"Terminal", terminalCheck->isChecked() );
3949 TQString temp = terminalEdit->text();
3950 if (d->nocloseonexitCheck )
3951 if ( d->nocloseonexitCheck->isChecked() )
3952 temp += TQString::fromLatin1(
"--noclose ");
3953 temp = temp.stripWhiteSpace();
3954 config.writeEntry(
"TerminalOptions", temp );
3955 config.writeEntry(
"X-TDE-SubstituteUID", suidCheck->isChecked() );
3956 config.writeEntry(
"X-TDE-Username", suidEdit->text() );
3960 void KExecPropsPlugin::slotBrowseExec()
3963 TQString::null, d->m_frame );
3967 if ( !f.isLocalFile()) {
3968 KMessageBox::sorry(d->m_frame, i18n(
"Only executables on local file systems are supported."));
3972 TQString path = f.path();
3973 KRun::shellQuote( path );
3974 execEdit->setText( path );
3977 class TDEApplicationPropsPlugin::TDEApplicationPropsPluginPrivate
3980 TDEApplicationPropsPluginPrivate()
3982 m_kdesktopMode = TQCString(tqApp->name()) ==
"kdesktop";
3984 ~TDEApplicationPropsPluginPrivate()
3989 bool m_kdesktopMode;
3995 d =
new TDEApplicationPropsPluginPrivate;
3996 d->m_frame =
properties->addPage(i18n(
"&Application"));
3997 TQVBoxLayout *toplayout =
new TQVBoxLayout( d->m_frame, 0, KDialog::spacingHint());
4002 addExtensionButton =
new TQPushButton( TQString::null, d->m_frame );
4003 iconSet = SmallIconSet(
"back" );
4004 addExtensionButton->setIconSet( iconSet );
4005 pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
4006 addExtensionButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
4007 connect( addExtensionButton, TQT_SIGNAL( clicked() ),
4008 TQT_SLOT( slotAddExtension() ) );
4010 delExtensionButton =
new TQPushButton( TQString::null, d->m_frame );
4011 iconSet = SmallIconSet(
"forward" );
4012 delExtensionButton->setIconSet( iconSet );
4013 delExtensionButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
4014 connect( delExtensionButton, TQT_SIGNAL( clicked() ),
4015 TQT_SLOT( slotDelExtension() ) );
4019 TQGridLayout *grid =
new TQGridLayout(2, 2);
4020 grid->setColStretch(1, 1);
4021 toplayout->addLayout(TQT_TQLAYOUT(grid));
4023 if ( d->m_kdesktopMode )
4030 l =
new TQLabel(i18n(
"Name:"), d->m_frame,
"Label_4" );
4031 grid->addWidget(l, 0, 0);
4033 nameEdit =
new KLineEdit( d->m_frame,
"LineEdit_3" );
4034 grid->addWidget(nameEdit, 0, 1);
4037 l =
new TQLabel(i18n(
"Description:"), d->m_frame,
"Label_5" );
4038 grid->addWidget(l, 1, 0);
4040 genNameEdit =
new KLineEdit( d->m_frame,
"LineEdit_4" );
4041 grid->addWidget(genNameEdit, 1, 1);
4043 l =
new TQLabel(i18n(
"Comment:"), d->m_frame,
"Label_3" );
4044 grid->addWidget(l, 2, 0);
4046 commentEdit =
new KLineEdit( d->m_frame,
"LineEdit_2" );
4047 grid->addWidget(commentEdit, 2, 1);
4049 l =
new TQLabel(i18n(
"File types:"), d->m_frame);
4050 toplayout->addWidget(l, 0, AlignLeft);
4052 grid =
new TQGridLayout(4, 3);
4053 grid->setColStretch(0, 1);
4054 grid->setColStretch(2, 1);
4055 grid->setRowStretch( 0, 1 );
4056 grid->setRowStretch( 3, 1 );
4057 toplayout->addLayout(TQT_TQLAYOUT(grid), 2);
4059 extensionsList =
new TQListBox( d->m_frame );
4060 extensionsList->setSelectionMode( TQListBox::Extended );
4061 grid->addMultiCellWidget(extensionsList, 0, 3, 0, 0);
4063 grid->addWidget(addExtensionButton, 1, 1);
4064 grid->addWidget(delExtensionButton, 2, 1);
4066 availableExtensionsList =
new TQListBox( d->m_frame );
4067 availableExtensionsList->setSelectionMode( TQListBox::Extended );
4068 grid->addMultiCellWidget(availableExtensionsList, 0, 3, 2, 2);
4072 if ( !f.open( IO_ReadOnly ) )
4076 KDesktopFile config( path );
4077 TQString commentStr = config.readComment();
4078 TQString genNameStr = config.readGenericName();
4080 TQStringList selectedTypes = config.readListEntry(
"X-TDE-ServiceTypes" );
4082 selectedTypes += config.readListEntry(
"MimeType",
';' );
4084 TQString nameStr = config.readName();
4085 if ( nameStr.isEmpty() || d->m_kdesktopMode ) {
4092 commentEdit->setText( commentStr );
4093 genNameEdit->setText( genNameStr );
4095 nameEdit->setText( nameStr );
4097 selectedTypes.sort();
4098 TQStringList::Iterator sit = selectedTypes.begin();
4099 for( ; sit != selectedTypes.end(); ++sit ) {
4100 if ( !((*sit).isEmpty()) )
4101 extensionsList->insertItem( *sit );
4104 KMimeType::List mimeTypes = KMimeType::allMimeTypes();
4105 TQValueListIterator<KMimeType::Ptr> it2 = mimeTypes.begin();
4106 for ( ; it2 != mimeTypes.end(); ++it2 )
4107 addMimeType ( (*it2)->name() );
4111 connect( extensionsList, TQT_SIGNAL( highlighted(
int ) ),
4112 this, TQT_SLOT( updateButton() ) );
4113 connect( availableExtensionsList, TQT_SIGNAL( highlighted(
int ) ),
4114 this, TQT_SLOT( updateButton() ) );
4116 connect( addExtensionButton, TQT_SIGNAL( clicked() ),
4117 this, TQT_SIGNAL(
changed() ) );
4118 connect( delExtensionButton, TQT_SIGNAL( clicked() ),
4119 this, TQT_SIGNAL(
changed() ) );
4121 connect( nameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4122 this, TQT_SIGNAL(
changed() ) );
4123 connect( commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4124 this, TQT_SIGNAL(
changed() ) );
4125 connect( genNameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4126 this, TQT_SIGNAL(
changed() ) );
4127 connect( availableExtensionsList, TQT_SIGNAL( selected(
int ) ),
4128 this, TQT_SIGNAL(
changed() ) );
4129 connect( extensionsList, TQT_SIGNAL( selected(
int ) ),
4130 this, TQT_SIGNAL(
changed() ) );
4133 TDEApplicationPropsPlugin::~TDEApplicationPropsPlugin()
4143 void TDEApplicationPropsPlugin::updateButton()
4145 addExtensionButton->setEnabled(availableExtensionsList->currentItem()>-1);
4146 delExtensionButton->setEnabled(extensionsList->currentItem()>-1);
4149 void TDEApplicationPropsPlugin::addMimeType(
const TQString & name )
4155 for ( uint i = 0; i < extensionsList->count(); i++ )
4156 if ( extensionsList->text( i ) == name )
4161 availableExtensionsList->insertItem( name );
4162 availableExtensionsList->sort();
4166 bool TDEApplicationPropsPlugin::supports( KFileItemList _items )
4169 return KExecPropsPlugin::supports( _items );
4178 if ( !f.open( IO_ReadWrite ) ) {
4179 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not "
4180 "have sufficient access to write to <b>%1</b>.</qt>").arg(path));
4185 KSimpleConfig config( path );
4186 config.setDesktopGroup();
4187 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
4188 config.writeEntry(
"Comment", commentEdit->text() );
4189 config.writeEntry(
"Comment", commentEdit->text(),
true,
false, true );
4190 config.writeEntry(
"GenericName", genNameEdit->text() );
4191 config.writeEntry(
"GenericName", genNameEdit->text(),
true,
false, true );
4193 TQStringList selectedTypes;
4194 for ( uint i = 0; i < extensionsList->count(); i++ )
4195 selectedTypes.append( extensionsList->text( i ) );
4197 config.writeEntry(
"MimeType", selectedTypes,
';' );
4198 config.writeEntry(
"X-TDE-ServiceTypes",
"" );
4201 TQString nameStr = nameEdit ? nameEdit->text() : TQString::null;
4202 if ( nameStr.isEmpty() )
4205 config.writeEntry(
"Name", nameStr );
4206 config.writeEntry(
"Name", nameStr,
true,
false,
true );
4211 void TDEApplicationPropsPlugin::slotAddExtension()
4213 TQListBoxItem *item = availableExtensionsList->firstItem();
4214 TQListBoxItem *nextItem;
4218 nextItem = item->next();
4220 if ( item->isSelected() )
4222 extensionsList->insertItem( item->text() );
4223 availableExtensionsList->removeItem( availableExtensionsList->index( item ) );
4229 extensionsList->sort();
4233 void TDEApplicationPropsPlugin::slotDelExtension()
4235 TQListBoxItem *item = extensionsList->firstItem();
4236 TQListBoxItem *nextItem;
4240 nextItem = item->next();
4242 if ( item->isSelected() )
4244 availableExtensionsList->insertItem( item->text() );
4245 extensionsList->removeItem( extensionsList->index( item ) );
4251 availableExtensionsList->sort();
4257 #include "kpropertiesdialog.moc"