49 #include <sys/types.h>
60 #include <tqpushbutton.h>
61 #include <tqcheckbox.h>
62 #include <tqstrlist.h>
63 #include <tqstringlist.h>
64 #include <tqtextstream.h>
65 #include <tqpainter.h>
67 #include <tqcombobox.h>
68 #include <tqgroupbox.h>
69 #include <tqwhatsthis.h>
70 #include <tqtooltip.h>
72 #include <tqprogressbar.h>
74 #include <tqvaluevector.h>
78 #include <sys/param.h>
79 #ifdef HAVE_SYS_MOUNT_H
80 #include <sys/mount.h>
82 #ifdef HAVE_SYS_XATTR_H
83 #include <sys/xattr.h>
88 #include <kapplication.h>
91 #include <kdirwatch.h>
92 #include <kdirnotify_stub.h>
93 #include <kdiskfreesp.h>
95 #include <kdesktopfile.h>
96 #include <kicondialog.h>
98 #include <kurlrequester.h>
101 #include <kglobalsettings.h>
102 #include <kstandarddirs.h>
104 #include <kio/chmodjob.h>
105 #include <kio/renamedlg.h>
106 #include <kio/netaccess.h>
107 #include <kio/kservicetypefactory.h>
108 #include <kfiledialog.h>
109 #include <kmimetype.h>
110 #include <kmountpoint.h>
111 #include <kiconloader.h>
112 #include <kmessagebox.h>
113 #include <kservice.h>
114 #include <kcompletion.h>
115 #include <klineedit.h>
116 #include <kseparator.h>
117 #include <ksqueezedtextlabel.h>
118 #include <klibloader.h>
120 #include <kparts/componentfactory.h>
121 #include <kmetaprops.h>
122 #include <kpreviewprops.h>
123 #include <kprocess.h>
125 #include <klistview.h>
127 #include "kfilesharedlg.h"
129 #include "kpropertiesdesktopbase.h"
130 #include "kpropertiesdesktopadvbase.h"
131 #include "kpropertiesmimetypebase.h"
133 #include "kacleditwidget.h"
136 #include "kpropertiesdialog.h"
139 # include <win32_utils.h>
142 static TQString nameFromFileName(TQString nameStr)
144 if ( nameStr.endsWith(
".desktop") )
145 nameStr.truncate( nameStr.length() - 8 );
146 if ( nameStr.endsWith(
".kdelnk") )
147 nameStr.truncate( nameStr.length() - 7 );
149 nameStr = KIO::decodeFileName( nameStr );
153 mode_t KFilePermissionsPropsPlugin::fperm[3][4] = {
154 {S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID},
155 {S_IRGRP, S_IWGRP, S_IXGRP, S_ISGID},
156 {S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX}
159 class KPropertiesDialog::KPropertiesDialogPrivate
162 KPropertiesDialogPrivate()
167 ~KPropertiesDialogPrivate()
171 TQWidget* fileSharePage;
175 TQWidget* parent,
const char* name,
176 bool modal,
bool autoShow)
177 : KDialogBase (KDialogBase::Tabbed, i18n(
"Properties for %1" ).arg(KIO::decodeFileName(item->url().fileName())),
178 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
181 d =
new KPropertiesDialogPrivate;
183 m_items.append(
new KFileItem(*item) );
185 m_singleUrl = item->url();
186 assert(!m_singleUrl.isEmpty());
188 init (modal, autoShow);
192 TQWidget* parent,
const char* name,
bool modal)
193 : KDialogBase (KDialogBase::Tabbed, i18n (
"Properties for %1").arg(title),
194 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
197 d =
new KPropertiesDialogPrivate;
203 TQWidget* parent,
const char* name,
204 bool modal,
bool autoShow)
205 : KDialogBase (KDialogBase::Tabbed,
208 _items.count()>1 ? i18n(
"<never used>",
"Properties for %n Selected Items",_items.count()) :
209 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_items.first()->url().fileName())),
210 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
213 d =
new KPropertiesDialogPrivate;
215 assert( !_items.isEmpty() );
216 m_singleUrl = _items.first()->url();
217 assert(!m_singleUrl.isEmpty());
219 KFileItemListIterator it ( _items );
221 for ( ; it.current(); ++it )
222 m_items.append(
new KFileItem( **it ) );
224 init (modal, autoShow);
227 #ifndef KDE_NO_COMPAT
229 TQWidget* parent,
const char* name,
230 bool modal,
bool autoShow)
231 : KDialogBase (KDialogBase::Tabbed,
232 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_url.fileName())),
233 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
234 parent, name, modal),
237 d =
new KPropertiesDialogPrivate;
241 KIO::NetAccess::stat(_url, entry, parent);
243 m_items.append(
new KFileItem( entry, _url ) );
244 init (modal, autoShow);
249 TQWidget* parent,
const char* name,
250 bool modal,
bool autoShow)
251 : KDialogBase (KDialogBase::Tabbed,
252 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_url.fileName())),
253 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
254 parent, name, modal),
257 d =
new KPropertiesDialogPrivate;
261 KIO::NetAccess::stat(_url, entry, parent);
263 m_items.append(
new KFileItem( entry, _url ) );
264 init (modal, autoShow);
268 const TQString& _defaultName,
269 TQWidget* parent,
const char* name,
270 bool modal,
bool autoShow)
271 : KDialogBase (KDialogBase::Tabbed,
272 i18n(
"Properties for %1" ).arg(KIO::decodeFileName(_tempUrl.fileName())),
273 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
274 parent, name, modal),
276 m_singleUrl( _tempUrl ),
277 m_defaultName( _defaultName ),
278 m_currentDir( _currentDir )
280 d =
new KPropertiesDialogPrivate;
282 assert(!m_singleUrl.isEmpty());
285 m_items.append(
new KFileItem( KFileItem::Unknown, KFileItem::Unknown, m_singleUrl ) );
286 init (modal, autoShow);
290 const char* name,
bool modal)
293 TQString localPath = item->localPath();
294 if (!localPath.isEmpty())
295 return showWin32FilePropertyDialog(localPath);
302 const char* name,
bool modal)
305 if (_url.isLocalFile())
306 return showWin32FilePropertyDialog( _url.path() );
313 const char* name,
bool modal)
315 if (_items.count()==1)
321 void KPropertiesDialog::init (
bool modal,
bool autoShow)
323 m_pageList.setAutoDelete(
true );
324 m_items.setAutoDelete(
true );
339 if (d->fileSharePage) {
340 showPage( pageIndex( d->fileSharePage));
345 d->fileSharePage = page;
353 for ( it=m_pageList.first(); it != 0L; it=m_pageList.next() )
357 plugin->setFileNameReadOnly( ro );
363 void KPropertiesDialog::slotStatResult( KIO::Job * )
375 connect (plugin, TQT_SIGNAL (changed ()),
376 plugin, TQT_SLOT (setDirty ()));
378 m_pageList.append (plugin);
386 KDesktopPropsPlugin::supports( _items ) ||
387 KBindingPropsPlugin::supports( _items ) ||
388 KURLPropsPlugin::supports( _items ) ||
389 KDevicePropsPlugin::supports( _items ) ||
397 d->m_aborted =
false;
400 if ( m_pageList.first()->isA(
"KFilePropsPlugin") )
401 filePropsPlugin = static_cast<KFilePropsPlugin *>(m_pageList.first());
406 for ( page = m_pageList.first(); page != 0L; page = m_pageList.next() )
407 if ( page->isDirty() && filePropsPlugin )
409 filePropsPlugin->setDirty();
417 for ( page = m_pageList.first(); page != 0L && !d->m_aborted; page = m_pageList.next() )
418 if ( page->isDirty() )
420 kdDebug( 250 ) <<
"applying changes for " << page->className() << endl;
425 kdDebug( 250 ) <<
"skipping page " << page->className() << endl;
427 if ( !d->m_aborted && filePropsPlugin )
448 void KPropertiesDialog::insertPages()
450 if (m_items.isEmpty())
465 if ( KDesktopPropsPlugin::supports( m_items ) )
471 if ( KBindingPropsPlugin::supports( m_items ) )
477 if ( KURLPropsPlugin::supports( m_items ) )
483 if ( KDevicePropsPlugin::supports( m_items ) )
501 if ( kapp->authorizeKAction(
"sharefile") &&
502 KFileSharePropsPlugin::supports( m_items ) )
510 if ( m_items.count() != 1 )
513 KFileItem *
item = m_items.first();
514 TQString mimetype = item->mimetype();
516 if ( mimetype.isEmpty() )
519 TQString query = TQString::fromLatin1(
520 "('KPropsDlg/Plugin' in ServiceTypes) and "
521 "((not exist [X-KDE-Protocol]) or "
522 " ([X-KDE-Protocol] == '%1' ) )" ).arg(item->url().protocol());
524 kdDebug( 250 ) <<
"trader query: " << query << endl;
525 KTrader::OfferList offers = KTrader::self()->query( mimetype, query );
526 KTrader::OfferList::ConstIterator it = offers.begin();
527 KTrader::OfferList::ConstIterator end = offers.end();
528 for (; it != end; ++it )
531 ::createInstanceFromLibrary<KPropsDlgPlugin>( (*it)->library().local8Bit().data(),
533 (*it)->name().latin1() );
543 Q_ASSERT( m_items.count() == 1 );
544 kdDebug(250) <<
"KPropertiesDialog::updateUrl (pre)" << _newUrl.url() << endl;
545 KURL newUrl = _newUrl;
546 emit
saveAs(m_singleUrl, newUrl);
547 kdDebug(250) <<
"KPropertiesDialog::updateUrl (post)" << newUrl.url() << endl;
549 m_singleUrl = newUrl;
550 m_items.first()->setURL( newUrl );
551 assert(!m_singleUrl.isEmpty());
554 for ( TQPtrListIterator<KPropsDlgPlugin> it(m_pageList); it.current(); ++it )
555 if ( it.current()->isA(
"KExecPropsPlugin") ||
556 it.current()->isA(
"KURLPropsPlugin") ||
557 it.current()->isA(
"KDesktopPropsPlugin"))
560 it.current()->setDirty();
567 Q_ASSERT( m_items.count() == 1 );
568 kdDebug(250) <<
"KPropertiesDialog::rename " << _name << endl;
571 if ( !m_currentDir.isEmpty() )
573 newUrl = m_currentDir;
574 newUrl.addPath( _name );
578 TQString tmpurl = m_singleUrl.url();
579 if ( tmpurl.at(tmpurl.length() - 1) ==
'/')
581 tmpurl.truncate( tmpurl.length() - 1);
583 newUrl.setFileName( _name );
593 class KPropsDlgPlugin::KPropsDlgPluginPrivate
596 KPropsDlgPluginPrivate()
599 ~KPropsDlgPluginPrivate()
607 : TQObject( _props, 0L )
609 d =
new KPropsDlgPluginPrivate;
611 fontHeight = 2*
properties->fontMetrics().height();
615 KPropsDlgPlugin::~KPropsDlgPlugin()
624 KURL url = _item->mostLocalURL( isLocal );
629 if ( !S_ISREG( _item->mode() ) )
632 TQString t( url.path() );
635 FILE *f = fopen( TQFile::encodeName(t),
"r" );
641 return ( (_item->mimetype() ==
"application/x-desktop")
642 || (_item->mimetype() ==
"media/builtin-mydocuments")
643 || (_item->mimetype() ==
"media/builtin-mycomputer")
644 || (_item->mimetype() ==
"media/builtin-mynetworkplaces")
645 || (_item->mimetype() ==
"media/builtin-printers")
646 || (_item->mimetype() ==
"media/builtin-trash")
647 || (_item->mimetype() ==
"media/builtin-webbrowser") );
650 void KPropsDlgPlugin::setDirty(
bool b )
655 void KPropsDlgPlugin::setDirty()
660 bool KPropsDlgPlugin::isDirty()
const
667 kdWarning(250) <<
"applyChanges() not implemented in page !" << endl;
672 class KFilePropsPlugin::KFilePropsPluginPrivate
675 KFilePropsPluginPrivate()
678 dirSizeUpdateTimer = 0L;
680 m_freeSpaceLabel = 0;
682 ~KFilePropsPluginPrivate()
689 TQTimer *dirSizeUpdateTimer;
695 TQLabel *m_freeSpaceLabel;
697 TQString oldFileName;
704 d =
new KFilePropsPluginPrivate;
706 d->bIconChanged =
false;
707 d->bKDesktopMode = (TQCString(tqApp->name()) ==
"kdesktop");
709 kdDebug(250) <<
"KFilePropsPlugin::KFilePropsPlugin bMultiple=" << d->bMultiple << endl;
715 KURL url = item->mostLocalURL( isLocal );
716 bool isReallyLocal = item->url().isLocalFile();
718 kdDebug() <<
"url=" << url <<
" bDesktopFile=" << bDesktopFile <<
" isLocal=" << isLocal <<
" isReallyLocal=" << isReallyLocal << endl;
719 mode_t mode = item->mode();
720 bool hasDirs = item->isDir() && !item->isLink();
721 bool hasRoot = url.path() == TQString::fromLatin1(
"/");
722 TQString iconStr = KMimeType::iconForURL(url, mode);
725 TQString mimeComment = item->mimeComment();
726 d->mimeType = item->mimetype();
728 KIO::filesize_t totalSize = item->size(hasTotalSize);
729 TQString magicMimeComment;
731 KMimeType::Ptr magicMimeType = KMimeType::findByFileContent( url.path() );
732 if ( magicMimeType->name() != KMimeType::defaultMimeType() ) {
733 magicMimeComment = magicMimeType->comment();
738 TQString filename = TQString::null;
739 bool isTrash =
false;
740 bool isDevice =
false;
741 m_bFromTemplate =
false;
744 uint iDirCount = hasDirs ? 1 : 0;
745 uint iFileCount = 1-iDirCount;
747 d->m_frame =
properties->addPage (i18n(
"&General"));
749 TQVBoxLayout *vbl =
new TQVBoxLayout( d->m_frame, 0,
750 KDialog::spacingHint(),
"vbl");
751 TQGridLayout *grid =
new TQGridLayout(0, 3);
752 grid->setColStretch(0, 0);
753 grid->setColStretch(1, 0);
754 grid->setColStretch(2, 1);
755 grid->addColSpacing(1, KDialog::spacingHint());
756 vbl->addLayout(TQT_TQLAYOUT(grid));
762 if ( !m_bFromTemplate ) {
763 isTrash = (
properties->
kurl().protocol().find(
"trash", 0,
false)==0 );
779 determineRelativePath( path );
784 if ( filename.isEmpty() ) {
785 filename = item->name();
787 m_bFromTemplate =
true;
790 d->oldFileName = filename;
793 filename = nameFromFileName( filename );
795 if ( d->bKDesktopMode && d->bDesktopFile ) {
796 KDesktopFile config( url.path(),
true );
797 if ( config.hasKey(
"Name" ) ) {
798 filename = config.readName();
808 KFileItemListIterator it( items );
809 for ( ++it ; it.current(); ++it )
811 KURL url = (*it)->url();
812 kdDebug(250) <<
"KFilePropsPlugin::KFilePropsPlugin " << url.prettyURL() << endl;
815 if ( url.isLocalFile() != isLocal )
818 bDesktopFile =
false;
819 if ( (*it)->mode() != mode )
821 if ( KMimeType::iconForURL(url, mode) != iconStr )
822 iconStr =
"kmultiple";
823 if ( url.directory() != directory )
824 directory = TQString::null;
825 if ( url.protocol() != protocol )
826 protocol = TQString::null;
827 if ( !mimeComment.isNull() && (*it)->mimeComment() != mimeComment )
828 mimeComment = TQString::null;
829 if ( isLocal && !magicMimeComment.isNull() ) {
830 KMimeType::Ptr magicMimeType = KMimeType::findByFileContent( url.path() );
831 if ( magicMimeType->comment() != magicMimeComment )
832 magicMimeComment = TQString::null;
835 if ( url.path() == TQString::fromLatin1(
"/") )
837 if ( (*it)->isDir() && !(*it)->isLink() )
846 totalSize += (*it)->size(hasSize);
847 hasTotalSize = hasTotalSize || hasSize;
852 if (!isReallyLocal && !protocol.isEmpty())
856 directory += protocol;
860 if ( !isDevice && !isTrash && (bDesktopFile || S_ISDIR(mode)) && !d->bMultiple )
863 int bsize = 66 + 2 * iconButton->style().pixelMetric(TQStyle::PM_ButtonMargin);
864 iconButton->setFixedSize(bsize, bsize);
869 TQString iconStr = KMimeType::findByURL( url, mode )->icon( url, isLocal );
870 if ( bDesktopFile && isLocal )
872 KDesktopFile config( url.path(), true );
873 config.setDesktopGroup();
874 iconStr = config.readEntry(
"Icon" );
875 if ( config.hasDeviceType() )
876 iconButton->
setIconType( KIcon::Desktop, KIcon::Device );
878 iconButton->
setIconType( KIcon::Desktop, KIcon::Application );
880 iconButton->
setIconType( KIcon::Desktop, KIcon::FileSystem );
882 iconArea = iconButton;
883 connect( iconButton, TQT_SIGNAL( iconChanged(TQString) ),
884 this, TQT_SLOT( slotIconChanged() ) );
886 TQLabel *iconLabel =
new TQLabel( d->m_frame );
887 int bsize = 66 + 2 * iconLabel->style().pixelMetric(TQStyle::PM_ButtonMargin);
888 iconLabel->setFixedSize(bsize, bsize);
889 iconLabel->setPixmap( KGlobal::iconLoader()->loadIcon( iconStr, KIcon::Desktop, 48) );
890 iconArea = iconLabel;
892 grid->addWidget(iconArea, curRow, 0, Qt::AlignLeft);
894 if (d->bMultiple || isTrash || isDevice || hasRoot)
896 TQLabel *lab =
new TQLabel(d->m_frame );
898 lab->setText( KIO::itemsSummaryString( iFileCount + iDirCount, iFileCount, iDirCount, 0,
false ) );
900 lab->setText( filename );
904 d->m_lined =
new KLineEdit( d->m_frame );
905 d->m_lined->setText(filename);
906 nameArea = d->m_lined;
907 d->m_lined->setFocus();
911 KServiceTypeFactory::self()->findFromPattern( filename, &pattern );
912 if (!pattern.isEmpty() && pattern.at(0)==
'*' && pattern.find(
'*',1)==-1)
913 d->m_lined->setSelection(0, filename.length()-pattern.stripWhiteSpace().length()+1);
916 int lastDot = filename.findRev(
'.');
918 d->m_lined->setSelection(0, lastDot);
921 connect( d->m_lined, TQT_SIGNAL( textChanged(
const TQString & ) ),
922 this, TQT_SLOT( nameFileChanged(
const TQString & ) ) );
925 grid->addWidget(nameArea, curRow++, 2);
927 KSeparator* sep =
new KSeparator( KSeparator::HLine, d->m_frame);
928 grid->addMultiCellWidget(sep, curRow, curRow, 0, 2);
932 if ( !mimeComment.isEmpty() && !isDevice && !isTrash)
934 l =
new TQLabel(i18n(
"Type:"), d->m_frame );
936 grid->addWidget(l, curRow, 0);
938 TQHBox *box =
new TQHBox(d->m_frame);
940 l =
new TQLabel(mimeComment, box );
944 TQPushButton *button =
new TQPushButton(box);
946 TQIconSet iconSet = SmallIconSet(TQString::fromLatin1(
"configure"));
947 TQPixmap pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
948 button->setIconSet( iconSet );
949 button->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
950 if ( d->mimeType == KMimeType::defaultMimeType() )
951 TQToolTip::add(button, i18n(
"Create new file type"));
953 TQToolTip::add(button, i18n(
"Edit file type"));
955 connect( button, TQT_SIGNAL( clicked() ), TQT_SLOT( slotEditFileType() ));
957 if (!kapp->authorizeKAction(
"editfiletype"))
961 grid->addWidget(box, curRow++, 2);
964 if ( !magicMimeComment.isEmpty() && magicMimeComment != mimeComment )
966 l =
new TQLabel(i18n(
"Contents:"), d->m_frame );
967 grid->addWidget(l, curRow, 0);
969 l =
new TQLabel(magicMimeComment, d->m_frame );
970 grid->addWidget(l, curRow++, 2);
973 if ( !directory.isEmpty() )
975 l =
new TQLabel( i18n(
"Location:"), d->m_frame );
976 grid->addWidget(l, curRow, 0);
978 l =
new KSqueezedTextLabel( d->m_frame );
979 l->setText( directory );
980 grid->addWidget(l, curRow++, 2);
983 if( hasDirs || hasTotalSize ) {
984 l =
new TQLabel(i18n(
"Size:"), d->m_frame );
985 grid->addWidget(l, curRow, 0);
987 m_sizeLabel =
new TQLabel( d->m_frame );
988 grid->addWidget( m_sizeLabel, curRow++, 2 );
996 m_sizeLabel->setText(KIO::convertSizeWithBytes(totalSize));
999 m_sizeDetermineButton = 0L;
1000 m_sizeStopButton = 0L;
1004 TQHBoxLayout * sizelay =
new TQHBoxLayout(KDialog::spacingHint());
1005 grid->addLayout( sizelay, curRow++, 2 );
1008 m_sizeDetermineButton =
new TQPushButton( i18n(
"Calculate"), d->m_frame );
1009 m_sizeStopButton =
new TQPushButton( i18n(
"Stop"), d->m_frame );
1010 connect( m_sizeDetermineButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotSizeDetermine() ) );
1011 connect( m_sizeStopButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotSizeStop() ) );
1012 sizelay->addWidget(m_sizeDetermineButton, 0);
1013 sizelay->addWidget(m_sizeStopButton, 0);
1014 sizelay->addStretch(10);
1017 if ( isLocal && !hasRoot )
1019 m_sizeDetermineButton->setText( i18n(
"Refresh") );
1020 slotSizeDetermine();
1023 m_sizeStopButton->setEnabled(
false );
1026 if (!d->bMultiple && item->isLink()) {
1027 l =
new TQLabel(i18n(
"Points to:"), d->m_frame );
1028 grid->addWidget(l, curRow, 0);
1030 l =
new KSqueezedTextLabel(item->linkDest(), d->m_frame );
1031 grid->addWidget(l, curRow++, 2);
1038 time_t tim = item->time(KIO::UDS_CREATION_TIME, hasTime);
1041 l =
new TQLabel(i18n(
"Created:"), d->m_frame );
1042 grid->addWidget(l, curRow, 0);
1044 dt.setTime_t( tim );
1045 l =
new TQLabel(KGlobal::locale()->formatDateTime(dt), d->m_frame );
1046 grid->addWidget(l, curRow++, 2);
1049 tim = item->time(KIO::UDS_MODIFICATION_TIME, hasTime);
1052 l =
new TQLabel(i18n(
"Modified:"), d->m_frame );
1053 grid->addWidget(l, curRow, 0);
1055 dt.setTime_t( tim );
1056 l =
new TQLabel(KGlobal::locale()->formatDateTime(dt), d->m_frame );
1057 grid->addWidget(l, curRow++, 2);
1060 tim = item->time(KIO::UDS_ACCESS_TIME, hasTime);
1063 l =
new TQLabel(i18n(
"Accessed:"), d->m_frame );
1064 grid->addWidget(l, curRow, 0);
1066 dt.setTime_t( tim );
1067 l =
new TQLabel(KGlobal::locale()->formatDateTime(dt), d->m_frame );
1068 grid->addWidget(l, curRow++, 2);
1072 if ( isLocal && hasDirs )
1074 sep =
new KSeparator( KSeparator::HLine, d->m_frame);
1075 grid->addMultiCellWidget(sep, curRow, curRow, 0, 2);
1078 TQString mountPoint = KIO::findPathMountPoint( url.path() );
1080 if (mountPoint !=
"/")
1082 l =
new TQLabel(i18n(
"Mounted on:"), d->m_frame );
1083 grid->addWidget(l, curRow, 0);
1085 l =
new KSqueezedTextLabel( mountPoint, d->m_frame );
1086 grid->addWidget( l, curRow++, 2 );
1089 l =
new TQLabel(i18n(
"Free disk space:"), d->m_frame );
1090 grid->addWidget(l, curRow, 0);
1092 d->m_freeSpaceLabel =
new TQLabel( d->m_frame );
1093 grid->addWidget( d->m_freeSpaceLabel, curRow++, 2 );
1096 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
1097 const unsigned long&,
const TQString& ) ),
1098 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
1099 const unsigned long&,
const TQString& ) ) );
1100 job->
readDF( mountPoint );
1111 void KFilePropsPlugin::setFileNameReadOnly(
bool ro )
1115 d->m_lined->setReadOnly( ro );
1119 TQPushButton *button =
properties->actionButton(KDialogBase::Ok);
1126 void KFilePropsPlugin::slotEditFileType()
1130 if ( d->mimeType == KMimeType::defaultMimeType() ) {
1131 int pos = d->oldFileName.findRev(
'.' );
1133 mime =
"*" + d->oldFileName.mid(pos);
1140 TQString keditfiletype = TQString::fromLatin1(
"keditfiletype");
1141 KRun::runCommand( keditfiletype
1142 +
" --parent " + TQString::number( (ulong)
properties->topLevelWidget()->winId())
1143 +
" " + KProcess::quote(mime),
1144 keditfiletype, keditfiletype );
1148 void KFilePropsPlugin::slotIconChanged()
1150 d->bIconChanged =
true;
1154 void KFilePropsPlugin::nameFileChanged(
const TQString &text )
1160 void KFilePropsPlugin::determineRelativePath(
const TQString & path )
1166 m_sRelativePath =KGlobal::dirs()->relativeLocation(
"mime", path);
1167 if (m_sRelativePath.startsWith(
"/"))
1168 m_sRelativePath = TQString::null;
1172 m_sRelativePath =KGlobal::dirs()->relativeLocation(
"apps", path);
1173 if (m_sRelativePath.startsWith(
"/"))
1175 m_sRelativePath =KGlobal::dirs()->relativeLocation(
"xdgdata-apps", path);
1176 if (m_sRelativePath.startsWith(
"/"))
1177 m_sRelativePath = TQString::null;
1179 m_sRelativePath = path;
1182 if ( m_sRelativePath.isEmpty() )
1185 kdWarning(250) <<
"Warning : editing a mimetype file out of the mimetype dirs!" << endl;
1189 void KFilePropsPlugin::slotFoundMountPoint(
const TQString&,
1190 unsigned long kBSize,
1192 unsigned long kBAvail )
1194 d->m_freeSpaceLabel->setText(
1196 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
1197 .arg(KIO::convertSizeFromKB(kBAvail))
1198 .arg(KIO::convertSizeFromKB(kBSize))
1199 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
1204 void KFilePropsPlugin::slotFoundMountPoint(
const unsigned long& kBSize,
1205 const unsigned long& ,
1206 const unsigned long& kBAvail,
1209 d->m_freeSpaceLabel->setText(
1211 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
1212 .arg(KIO::convertSizeFromKB(kBAvail))
1213 .arg(KIO::convertSizeFromKB(kBSize))
1214 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
1217 void KFilePropsPlugin::slotDirSizeUpdate()
1219 KIO::filesize_t totalSize = d->dirSizeJob->totalSize();
1220 KIO::filesize_t totalFiles = d->dirSizeJob->totalFiles();
1221 KIO::filesize_t totalSubdirs = d->dirSizeJob->totalSubdirs();
1222 m_sizeLabel->setText( i18n(
"Calculating... %1 (%2)\n%3, %4")
1223 .arg(KIO::convertSize(totalSize))
1224 .arg(KGlobal::locale()->formatNumber(totalSize, 0))
1225 .arg(i18n(
"1 file",
"%n files",totalFiles))
1226 .arg(i18n(
"1 sub-folder",
"%n sub-folders",totalSubdirs)));
1229 void KFilePropsPlugin::slotDirSizeFinished( KIO::Job * job )
1232 m_sizeLabel->setText( job->errorString() );
1235 KIO::filesize_t totalSize =
static_cast<KDirSize*
>(job)->totalSize();
1236 KIO::filesize_t totalFiles =
static_cast<KDirSize*
>(job)->totalFiles();
1237 KIO::filesize_t totalSubdirs =
static_cast<KDirSize*
>(job)->totalSubdirs();
1238 m_sizeLabel->setText( TQString::fromLatin1(
"%1 (%2)\n%3, %4")
1239 .arg(KIO::convertSize(totalSize))
1240 .arg(KGlobal::locale()->formatNumber(totalSize, 0))
1241 .arg(i18n(
"1 file",
"%n files",totalFiles))
1242 .arg(i18n(
"1 sub-folder",
"%n sub-folders",totalSubdirs)));
1244 m_sizeStopButton->setEnabled(
false);
1246 m_sizeDetermineButton->setText( i18n(
"Refresh") );
1247 m_sizeDetermineButton->setEnabled(
true);
1249 delete d->dirSizeUpdateTimer;
1250 d->dirSizeUpdateTimer = 0L;
1253 void KFilePropsPlugin::slotSizeDetermine()
1255 m_sizeLabel->setText( i18n(
"Calculating...") );
1256 kdDebug(250) <<
" KFilePropsPlugin::slotSizeDetermine() properties->item()=" <<
properties->
item() << endl;
1257 kdDebug(250) <<
" URL=" <<
properties->
item()->url().url() << endl;
1259 d->dirSizeUpdateTimer =
new TQTimer(
this);
1260 connect( d->dirSizeUpdateTimer, TQT_SIGNAL( timeout() ),
1261 TQT_SLOT( slotDirSizeUpdate() ) );
1262 d->dirSizeUpdateTimer->start(500);
1263 connect( d->dirSizeJob, TQT_SIGNAL( result( KIO::Job * ) ),
1264 TQT_SLOT( slotDirSizeFinished( KIO::Job * ) ) );
1265 m_sizeStopButton->setEnabled(
true);
1266 m_sizeDetermineButton->setEnabled(
false);
1269 if ( d->m_freeSpaceLabel )
1273 KURL url = item->mostLocalURL( isLocal );
1274 TQString mountPoint = KIO::findPathMountPoint( url.path() );
1277 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
1278 const unsigned long&,
const TQString& ) ),
1279 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
1280 const unsigned long&,
const TQString& ) ) );
1281 job->readDF( mountPoint );
1285 void KFilePropsPlugin::slotSizeStop()
1287 if ( d->dirSizeJob )
1289 m_sizeLabel->setText( i18n(
"Stopped") );
1290 d->dirSizeJob->kill();
1293 if ( d->dirSizeUpdateTimer )
1294 d->dirSizeUpdateTimer->stop();
1296 m_sizeStopButton->setEnabled(
false);
1297 m_sizeDetermineButton->setEnabled(
true);
1300 KFilePropsPlugin::~KFilePropsPlugin()
1311 void qt_enter_modal( TQWidget *widget );
1312 void qt_leave_modal( TQWidget *widget );
1316 if ( d->dirSizeJob ) {
1320 kdDebug(250) <<
"KFilePropsPlugin::applyChanges" << endl;
1322 if (nameArea->inherits(TQLINEEDIT_OBJECT_NAME_STRING))
1324 TQString n = ((TQLineEdit *) nameArea)->text();
1326 while ( n[n.length()-1].isSpace() )
1327 n.truncate( n.length() - 1 );
1330 KMessageBox::sorry(
properties, i18n(
"The new file name is empty."));
1336 kdDebug(250) <<
"oldname = " << oldName << endl;
1337 kdDebug(250) <<
"newname = " << n << endl;
1338 if ( oldName != n || m_bFromTemplate ) {
1339 KIO::Job * job = 0L;
1342 TQString newFileName = KIO::encodeFileName(n);
1343 if (d->bDesktopFile && !newFileName.endsWith(
".desktop") && !newFileName.endsWith(
".kdelnk"))
1344 newFileName +=
".desktop";
1350 if ( !m_sRelativePath.isEmpty() ) {
1354 kdDebug(250) <<
"New URL = " <<
properties->
kurl().url() << endl;
1355 kdDebug(250) <<
"old = " << oldurl.url() << endl;
1358 if ( !m_bFromTemplate ) {
1365 connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
1366 TQT_SLOT( slotCopyFinished( KIO::Job * ) ) );
1367 connect( job, TQT_SIGNAL( renamed( KIO::Job *,
const KURL &,
const KURL & ) ),
1368 TQT_SLOT( slotFileRenamed( KIO::Job *,
const KURL &,
const KURL & ) ) );
1370 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
1371 qt_enter_modal(&dummy);
1372 tqApp->enter_loop();
1373 qt_leave_modal(&dummy);
1378 if ( !m_sRelativePath.isEmpty() ) {
1384 slotCopyFinished( 0L );
1387 void KFilePropsPlugin::slotCopyFinished( KIO::Job * job )
1389 kdDebug(250) <<
"KFilePropsPlugin::slotCopyFinished" << endl;
1396 job->showErrorDialog( d->m_frame );
1408 if (KBindingPropsPlugin::supports(
properties->
items()) && !m_sRelativePath.isEmpty())
1411 newURL.setPath( locateLocal(
"mime", m_sRelativePath) );
1414 else if (d->bDesktopFile && !m_sRelativePath.isEmpty())
1416 kdDebug(250) <<
"KFilePropsPlugin::slotCopyFinished " << m_sRelativePath << endl;
1418 newURL.setPath( KDesktopFile::locateLocal(m_sRelativePath) );
1419 kdDebug(250) <<
"KFilePropsPlugin::slotCopyFinished path=" << newURL.path() << endl;
1423 if ( d->bKDesktopMode && d->bDesktopFile ) {
1425 if ( d->oldFileName !=
properties->
kurl().fileName() || m_bFromTemplate ) {
1427 TQString nameStr = nameFromFileName(
properties->
kurl().fileName());
1428 config.writeEntry(
"Name", nameStr );
1429 config.writeEntry(
"Name", nameStr,
true,
false,
true );
1434 void KFilePropsPlugin::applyIconChanges()
1437 if ( !iconButton || !d->bIconChanged )
1442 url = KIO::NetAccess::mostLocalURL( url,
properties );
1443 if (url.isLocalFile()) {
1448 path = url.path(1) + TQString::fromLatin1(
".directory");
1456 TQString str = KMimeType::findByURL( url,
1458 true )->KServiceType::icon();
1461 if ( str != iconButton->icon() )
1462 sIcon = iconButton->icon();
1465 kdDebug(250) <<
"**" << path <<
"**" << endl;
1469 if ( !sIcon.isEmpty() || f.exists() )
1471 if ( !f.open( IO_ReadWrite ) ) {
1472 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not "
1473 "have sufficient access to write to <b>%1</b>.</qt>").arg(path));
1478 KDesktopFile cfg(path);
1479 kdDebug(250) <<
"sIcon = " << (sIcon) << endl;
1480 kdDebug(250) <<
"str = " << (str) << endl;
1481 cfg.writeEntry(
"Icon", sIcon );
1487 void KFilePropsPlugin::slotFileRenamed( KIO::Job *,
const KURL &,
const KURL & newUrl )
1501 for ( KFileItemListIterator it( items ); it.current(); ++it )
1502 lst.append((*it)->url());
1503 KDirNotify_stub allDirNotify(
"*",
"KDirNotify*");
1504 allDirNotify.FilesChanged( lst );
1507 class KFilePermissionsPropsPlugin::KFilePermissionsPropsPluginPrivate
1510 KFilePermissionsPropsPluginPrivate()
1513 ~KFilePermissionsPropsPluginPrivate()
1518 TQCheckBox *cbRecursive;
1519 TQLabel *explanationLabel;
1520 TQComboBox *ownerPermCombo, *groupPermCombo, *othersPermCombo;
1521 TQCheckBox *extraCheckbox;
1522 mode_t partialPermissions;
1523 KFilePermissionsPropsPlugin::PermissionsMode pmode;
1524 bool canChangePermissions;
1526 bool hasExtendedACL;
1529 bool fileSystemSupportsACLs;
1532 #define UniOwner (S_IRUSR|S_IWUSR|S_IXUSR)
1533 #define UniGroup (S_IRGRP|S_IWGRP|S_IXGRP)
1534 #define UniOthers (S_IROTH|S_IWOTH|S_IXOTH)
1535 #define UniRead (S_IRUSR|S_IRGRP|S_IROTH)
1536 #define UniWrite (S_IWUSR|S_IWGRP|S_IWOTH)
1537 #define UniExec (S_IXUSR|S_IXGRP|S_IXOTH)
1538 #define UniSpecial (S_ISUID|S_ISGID|S_ISVTX)
1541 const mode_t KFilePermissionsPropsPlugin::permissionsMasks[3] = {UniOwner, UniGroup, UniOthers};
1542 const mode_t KFilePermissionsPropsPlugin::standardPermissions[4] = { 0, UniRead, UniRead|UniWrite, (mode_t)-1 };
1545 const char *KFilePermissionsPropsPlugin::permissionsTexts[4][4] = {
1546 { I18N_NOOP(
"Forbidden"),
1547 I18N_NOOP(
"Can Read"),
1548 I18N_NOOP(
"Can Read & Write"),
1550 { I18N_NOOP(
"Forbidden"),
1551 I18N_NOOP(
"Can View Content"),
1552 I18N_NOOP(
"Can View & Modify Content"),
1555 { I18N_NOOP(
"Forbidden"),
1556 I18N_NOOP(
"Can View Content & Read"),
1557 I18N_NOOP(
"Can View/Read & Modify/Write"),
1565 d =
new KFilePermissionsPropsPluginPrivate;
1566 d->cbRecursive = 0L;
1567 grpCombo = 0L; grpEdit = 0;
1572 bool isTrash = (
properties->
kurl().protocol().find(
"trash", 0,
false)==0 );
1573 bool IamRoot = (geteuid() == 0);
1576 bool isLink = item->isLink();
1577 bool isDir = item->isDir();
1578 bool hasDir = item->isDir();
1579 permissions = item->permissions();
1580 d->partialPermissions = permissions;
1581 d->isIrregular = isIrregular(permissions, isDir, isLink);
1582 strOwner = item->user();
1583 strGroup = item->group();
1584 d->hasExtendedACL = item->ACL().isExtended() || item->defaultACL().isValid();
1585 d->extendedACL = item->ACL();
1586 d->defaultACL = item->defaultACL();
1587 d->fileSystemSupportsACLs =
false;
1593 KFileItemListIterator it( items );
1594 for ( ++it ; it.current(); ++it )
1596 if (!d->isIrregular)
1597 d->isIrregular |= isIrregular((*it)->permissions(),
1598 (*it)->isDir() == isDir,
1599 (*it)->isLink() == isLink);
1600 d->hasExtendedACL = d->hasExtendedACL || (*it)->hasExtendedACL();
1601 if ( (*it)->isLink() != isLink )
1603 if ( (*it)->isDir() != isDir )
1605 hasDir |= (*it)->isDir();
1606 if ( (*it)->permissions() != permissions )
1608 permissions &= (*it)->permissions();
1609 d->partialPermissions |= (*it)->permissions();
1611 if ( (*it)->user() != strOwner )
1612 strOwner = TQString::null;
1613 if ( (*it)->group() != strGroup )
1614 strGroup = TQString::null;
1619 d->pmode = PermissionsOnlyLinks;
1621 d->pmode = PermissionsOnlyDirs;
1623 d->pmode = PermissionsMixed;
1625 d->pmode = PermissionsOnlyFiles;
1628 d->partialPermissions = d->partialPermissions & ~permissions;
1630 bool isMyFile =
false;
1632 if (isLocal && !strOwner.isEmpty()) {
1633 struct passwd *myself = getpwuid( geteuid() );
1636 isMyFile = (strOwner == TQString::fromLocal8Bit(myself->pw_name));
1638 kdWarning() <<
"I don't exist ?! geteuid=" << geteuid() << endl;
1646 d->canChangePermissions = (isMyFile || IamRoot) && (!isLink);
1651 d->m_frame =
properties->addPage(i18n(
"&Permissions"));
1653 TQBoxLayout *box =
new TQVBoxLayout( d->m_frame, 0, KDialog::spacingHint() );
1659 TQPushButton* pbAdvancedPerm = 0;
1662 gb =
new TQGroupBox ( 0, Qt::Vertical, i18n(
"Access Permissions"), d->m_frame );
1663 gb->layout()->setSpacing(KDialog::spacingHint());
1664 gb->layout()->setMargin(KDialog::marginHint());
1665 box->addWidget (gb);
1667 gl =
new TQGridLayout (gb->layout(), 7, 2);
1668 gl->setColStretch(1, 1);
1670 l = d->explanationLabel =
new TQLabel(
"", gb );
1672 d->explanationLabel->setText(i18n(
"This file is a link and does not have permissions.",
1673 "All files are links and do not have permissions.",
1675 else if (!d->canChangePermissions)
1676 d->explanationLabel->setText(i18n(
"Only the owner can change permissions."));
1677 gl->addMultiCellWidget(l, 0, 0, 0, 1);
1679 lbl =
new TQLabel( i18n(
"O&wner:"), gb);
1680 gl->addWidget(lbl, 1, 0);
1681 l = d->ownerPermCombo =
new TQComboBox(gb);
1683 gl->addWidget(l, 1, 1);
1684 connect(l, TQT_SIGNAL( highlighted(
int) ),
this, TQT_SIGNAL(
changed() ));
1685 TQWhatsThis::add(l, i18n(
"Specifies the actions that the owner is allowed to do."));
1687 lbl =
new TQLabel( i18n(
"Gro&up:"), gb);
1688 gl->addWidget(lbl, 2, 0);
1689 l = d->groupPermCombo =
new TQComboBox(gb);
1691 gl->addWidget(l, 2, 1);
1692 connect(l, TQT_SIGNAL( highlighted(
int) ),
this, TQT_SIGNAL(
changed() ));
1693 TQWhatsThis::add(l, i18n(
"Specifies the actions that the members of the group are allowed to do."));
1695 lbl =
new TQLabel( i18n(
"O&thers:"), gb);
1696 gl->addWidget(lbl, 3, 0);
1697 l = d->othersPermCombo =
new TQComboBox(gb);
1699 gl->addWidget(l, 3, 1);
1700 connect(l, TQT_SIGNAL( highlighted(
int) ),
this, TQT_SIGNAL(
changed() ));
1701 TQWhatsThis::add(l, i18n(
"Specifies the actions that all users, who are neither "
1702 "owner nor in the group, are allowed to do."));
1705 l = d->extraCheckbox =
new TQCheckBox(hasDir ?
1706 i18n(
"Only own&er can rename and delete folder content") :
1707 i18n(
"Is &executable"),
1709 connect( d->extraCheckbox, TQT_SIGNAL( clicked() ),
this, TQT_SIGNAL(
changed() ) );
1710 gl->addWidget(l, 4, 1);
1711 TQWhatsThis::add(l, hasDir ? i18n(
"Enable this option to allow only the folder's owner to "
1712 "delete or rename the contained files and folders. Other "
1713 "users can only add new files, which requires the 'Modify "
1714 "Content' permission.")
1715 : i18n(
"Enable this option to mark the file as executable. This only makes "
1716 "sense for programs and scripts. It is required when you want to "
1719 TQLayoutItem *spacer = TQT_TQLAYOUTITEM(
new TQSpacerItem(0, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding));
1720 gl->addMultiCell(spacer, 5, 5, 0, 1);
1722 pbAdvancedPerm =
new TQPushButton(i18n(
"A&dvanced Permissions"), gb);
1723 gl->addMultiCellWidget(pbAdvancedPerm, 6, 6, 0, 1, Qt::AlignRight);
1724 connect(pbAdvancedPerm, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotShowAdvancedPermissions() ));
1727 d->extraCheckbox = 0;
1731 gb =
new TQGroupBox ( 0, Qt::Vertical, i18n(
"Ownership"), d->m_frame );
1732 gb->layout()->setSpacing(KDialog::spacingHint());
1733 gb->layout()->setMargin(KDialog::marginHint());
1734 box->addWidget (gb);
1736 gl =
new TQGridLayout (gb->layout(), 4, 3);
1737 gl->addRowSpacing(0, 10);
1740 l =
new TQLabel( i18n(
"User:"), gb );
1741 gl->addWidget (l, 1, 0);
1748 int i, maxEntries = 1000;
1749 struct passwd *user;
1755 if (IamRoot && isLocal)
1757 usrEdit =
new KLineEdit( gb );
1758 KCompletion *kcom = usrEdit->completionObject();
1759 kcom->setOrder(KCompletion::Sorted);
1761 for (i=0; ((user = getpwent()) != 0L) && (i < maxEntries); i++)
1762 kcom->addItem(TQString::fromLatin1(user->pw_name));
1764 usrEdit->setCompletionMode((i < maxEntries) ? KGlobalSettings::CompletionAuto :
1765 KGlobalSettings::CompletionNone);
1766 usrEdit->setText(strOwner);
1767 gl->addWidget(usrEdit, 1, 1);
1768 connect( usrEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
1769 this, TQT_SIGNAL(
changed() ) );
1773 l =
new TQLabel(strOwner, gb);
1774 gl->addWidget(l, 1, 1);
1779 TQStringList groupList;
1781 user = getpwuid(geteuid());
1783 strUser = user->pw_name;
1787 for (i=0; ((ge = getgrent()) != 0L) && (i < maxEntries); i++)
1790 groupList += TQString::fromLatin1(ge->gr_name);
1794 char ** members = ge->gr_mem;
1796 while ((member = *members) != 0L) {
1797 if (strUser == member) {
1798 groupList += TQString::fromLocal8Bit(ge->gr_name);
1809 ge = getgrgid (getegid());
1811 TQString name = TQString::fromLatin1(ge->gr_name);
1813 name.setNum(ge->gr_gid);
1814 if (groupList.find(name) == groupList.end())
1818 bool isMyGroup = groupList.contains(strGroup);
1824 groupList += strGroup;
1826 l =
new TQLabel( i18n(
"Group:"), gb );
1827 gl->addWidget (l, 2, 0);
1835 if (IamRoot && isLocal)
1837 grpEdit =
new KLineEdit(gb);
1838 KCompletion *kcom =
new KCompletion;
1839 kcom->setItems(groupList);
1840 grpEdit->setCompletionObject(kcom,
true);
1841 grpEdit->setAutoDeleteCompletionObject(
true );
1842 grpEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
1843 grpEdit->setText(strGroup);
1844 gl->addWidget(grpEdit, 2, 1);
1845 connect( grpEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
1846 this, TQT_SIGNAL(
changed() ) );
1848 else if ((groupList.count() > 1) && isMyFile && isLocal)
1850 grpCombo =
new TQComboBox(gb,
"combogrouplist");
1851 grpCombo->insertStringList(groupList);
1852 grpCombo->setCurrentItem(groupList.findIndex(strGroup));
1853 gl->addWidget(grpCombo, 2, 1);
1854 connect( grpCombo, TQT_SIGNAL( activated(
int ) ),
1855 this, TQT_SIGNAL(
changed() ) );
1859 l =
new TQLabel(strGroup, gb);
1860 gl->addWidget(l, 2, 1);
1863 gl->setColStretch(2, 10);
1866 if ( hasDir && !isLink && !isTrash )
1868 d->cbRecursive =
new TQCheckBox( i18n(
"Apply changes to all subfolders and their contents"), d->m_frame );
1869 connect( d->cbRecursive, TQT_SIGNAL( clicked() ),
this, TQT_SIGNAL(
changed() ) );
1870 box->addWidget( d->cbRecursive );
1873 updateAccessControls();
1876 if ( isTrash || !d->canChangePermissions )
1879 enableAccessControls(
false);
1880 if ( pbAdvancedPerm && !d->hasExtendedACL )
1881 pbAdvancedPerm->setEnabled(
false);
1884 box->addStretch (10);
1887 #ifdef USE_POSIX_ACL
1888 static bool fileSystemSupportsACL(
const TQCString& pathCString )
1890 bool fileSystemSupportsACLs =
false;
1893 fileSystemSupportsACLs = ( statfs( pathCString.data(), &buf ) == 0 ) && ( buf.f_flags & MNT_ACLS );
1895 fileSystemSupportsACLs =
1896 getxattr( pathCString.data(),
"system.posix_acl_access", NULL, 0 ) >= 0
1898 || (errno == ENODATA)
1901 || (errno == ENOATTR)
1905 return fileSystemSupportsACLs;
1910 void KFilePermissionsPropsPlugin::slotShowAdvancedPermissions() {
1912 bool isDir = (d->pmode == PermissionsOnlyDirs) || (d->pmode == PermissionsMixed);
1913 KDialogBase dlg(
properties, 0,
true, i18n(
"Advanced Permissions"),
1914 KDialogBase::Ok|KDialogBase::Cancel);
1920 TQVBox *mainVBox = dlg.makeVBoxMainWidget();
1923 gb =
new TQGroupBox ( 0, Qt::Vertical, i18n(
"Access Permissions"), mainVBox );
1924 gb->layout()->setSpacing(KDialog::spacingHint());
1925 gb->layout()->setMargin(KDialog::marginHint());
1927 gl =
new TQGridLayout (gb->layout(), 6, 6);
1928 gl->addRowSpacing(0, 10);
1930 TQValueVector<TQWidget*> theNotSpecials;
1932 l =
new TQLabel(i18n(
"Class"), gb );
1933 gl->addWidget(l, 1, 0);
1934 theNotSpecials.append( l );
1937 l =
new TQLabel( i18n(
"Show\nEntries"), gb );
1939 l =
new TQLabel( i18n(
"Read"), gb );
1940 gl->addWidget (l, 1, 1);
1941 theNotSpecials.append( l );
1942 TQString readWhatsThis;
1944 readWhatsThis = i18n(
"This flag allows viewing the content of the folder.");
1946 readWhatsThis = i18n(
"The Read flag allows viewing the content of the file.");
1947 TQWhatsThis::add(l, readWhatsThis);
1950 l =
new TQLabel( i18n(
"Write\nEntries"), gb );
1952 l =
new TQLabel( i18n(
"Write"), gb );
1953 gl->addWidget (l, 1, 2);
1954 theNotSpecials.append( l );
1955 TQString writeWhatsThis;
1957 writeWhatsThis = i18n(
"This flag allows adding, renaming and deleting of files. "
1958 "Note that deleting and renaming can be limited using the Sticky flag.");
1960 writeWhatsThis = i18n(
"The Write flag allows modifying the content of the file.");
1961 TQWhatsThis::add(l, writeWhatsThis);
1963 TQString execWhatsThis;
1965 l =
new TQLabel( i18n(
"Enter folder",
"Enter"), gb );
1966 execWhatsThis = i18n(
"Enable this flag to allow entering the folder.");
1969 l =
new TQLabel( i18n(
"Exec"), gb );
1970 execWhatsThis = i18n(
"Enable this flag to allow executing the file as a program.");
1972 TQWhatsThis::add(l, execWhatsThis);
1973 theNotSpecials.append( l );
1975 TQSize size = l->sizeHint();
1976 size.setWidth(size.width() + 15);
1977 l->setFixedSize(size);
1978 gl->addWidget (l, 1, 3);
1980 l =
new TQLabel( i18n(
"Special"), gb );
1981 gl->addMultiCellWidget(l, 1, 1, 4, 5);
1982 TQString specialWhatsThis;
1984 specialWhatsThis = i18n(
"Special flag. Valid for the whole folder, the exact "
1985 "meaning of the flag can be seen in the right hand column.");
1987 specialWhatsThis = i18n(
"Special flag. The exact meaning of the flag can be seen "
1988 "in the right hand column.");
1989 TQWhatsThis::add(l, specialWhatsThis);
1991 cl[0] =
new TQLabel( i18n(
"User"), gb );
1992 gl->addWidget (cl[0], 2, 0);
1993 theNotSpecials.append( cl[0] );
1995 cl[1] =
new TQLabel( i18n(
"Group"), gb );
1996 gl->addWidget (cl[1], 3, 0);
1997 theNotSpecials.append( cl[1] );
1999 cl[2] =
new TQLabel( i18n(
"Others"), gb );
2000 gl->addWidget (cl[2], 4, 0);
2001 theNotSpecials.append( cl[2] );
2003 l =
new TQLabel(i18n(
"Set UID"), gb);
2004 gl->addWidget(l, 2, 5);
2005 TQString setUidWhatsThis;
2007 setUidWhatsThis = i18n(
"If this flag is set, the owner of this folder will be "
2008 "the owner of all new files.");
2010 setUidWhatsThis = i18n(
"If this file is an executable and the flag is set, it will "
2011 "be executed with the permissions of the owner.");
2012 TQWhatsThis::add(l, setUidWhatsThis);
2014 l =
new TQLabel(i18n(
"Set GID"), gb);
2015 gl->addWidget(l, 3, 5);
2016 TQString setGidWhatsThis;
2018 setGidWhatsThis = i18n(
"If this flag is set, the group of this folder will be "
2019 "set for all new files.");
2021 setGidWhatsThis = i18n(
"If this file is an executable and the flag is set, it will "
2022 "be executed with the permissions of the group.");
2023 TQWhatsThis::add(l, setGidWhatsThis);
2025 l =
new TQLabel(i18n(
"File permission",
"Sticky"), gb);
2026 gl->addWidget(l, 4, 5);
2027 TQString stickyWhatsThis;
2029 stickyWhatsThis = i18n(
"If the Sticky flag is set on a folder, only the owner "
2030 "and root can delete or rename files. Otherwise everybody "
2031 "with write permissions can do this.");
2033 stickyWhatsThis = i18n(
"The Sticky flag on a file is ignored on Linux, but may "
2034 "be used on some systems");
2035 TQWhatsThis::add(l, stickyWhatsThis);
2037 mode_t aPermissions, aPartialPermissions;
2038 mode_t dummy1, dummy2;
2040 if (!d->isIrregular) {
2042 case PermissionsOnlyFiles:
2043 getPermissionMasks(aPartialPermissions,
2048 case PermissionsOnlyDirs:
2049 case PermissionsMixed:
2050 getPermissionMasks(dummy1,
2051 aPartialPermissions,
2055 case PermissionsOnlyLinks:
2056 aPermissions = UniRead | UniWrite | UniExec | UniSpecial;
2057 aPartialPermissions = 0;
2062 aPermissions = permissions;
2063 aPartialPermissions = d->partialPermissions;
2067 TQCheckBox *cba[3][4];
2068 for (
int row = 0; row < 3 ; ++row) {
2069 for (
int col = 0; col < 4; ++col) {
2070 TQCheckBox *cb =
new TQCheckBox( gb );
2071 if ( col != 3 ) theNotSpecials.append( cb );
2073 cb->setChecked(aPermissions & fperm[row][col]);
2074 if ( aPartialPermissions & fperm[row][col] )
2079 else if (d->cbRecursive && d->cbRecursive->isChecked())
2082 cb->setEnabled( d->canChangePermissions );
2083 gl->addWidget (cb, row+2, col+1);
2086 TQWhatsThis::add(cb, readWhatsThis);
2089 TQWhatsThis::add(cb, writeWhatsThis);
2092 TQWhatsThis::add(cb, execWhatsThis);
2097 TQWhatsThis::add(cb, setUidWhatsThis);
2100 TQWhatsThis::add(cb, setGidWhatsThis);
2103 TQWhatsThis::add(cb, stickyWhatsThis);
2110 gl->setColStretch(6, 10);
2112 #ifdef USE_POSIX_ACL
2113 KACLEditWidget *extendedACLs = 0;
2117 TQCString pathCString = TQFile::encodeName(
properties->
item()->url().path() );
2118 d->fileSystemSupportsACLs = fileSystemSupportsACL( pathCString );
2120 if ( d->fileSystemSupportsACLs ) {
2121 std::for_each( theNotSpecials.begin(), theNotSpecials.end(), std::mem_fun( &TQWidget::hide ) );
2122 extendedACLs =
new KACLEditWidget( mainVBox );
2123 if ( d->extendedACL.isValid() && d->extendedACL.isExtended() )
2124 extendedACLs->setACL( d->extendedACL );
2126 extendedACLs->setACL( KACL( aPermissions ) );
2128 if ( d->defaultACL.isValid() )
2129 extendedACLs->setDefaultACL( d->defaultACL );
2132 extendedACLs->setAllowDefaults(
true );
2133 if ( !d->canChangePermissions )
2134 extendedACLs->setReadOnly(
true );
2138 if (dlg.exec() != KDialogBase::Accepted)
2141 mode_t andPermissions = mode_t(~0);
2142 mode_t orPermissions = 0;
2143 for (
int row = 0; row < 3; ++row)
2144 for (
int col = 0; col < 4; ++col) {
2145 switch (cba[row][col]->state())
2147 case TQCheckBox::On:
2148 orPermissions |= fperm[row][col];
2150 case TQCheckBox::Off:
2151 andPermissions &= ~fperm[row][col];
2158 d->isIrregular =
false;
2160 for (KFileItemListIterator it(items); it.current(); ++it) {
2161 if (isIrregular(((*it)->permissions() & andPermissions) | orPermissions,
2162 (*it)->isDir(), (*it)->isLink())) {
2163 d->isIrregular =
true;
2168 permissions = orPermissions;
2169 d->partialPermissions = andPermissions;
2171 #ifdef USE_POSIX_ACL
2173 if ( extendedACLs ) {
2174 d->extendedACL = extendedACLs->getACL();
2175 d->defaultACL = extendedACLs->getDefaultACL();
2176 d->hasExtendedACL = d->extendedACL.isExtended() || d->defaultACL.isValid();
2177 permissions = d->extendedACL.basePermissions();
2178 permissions |= ( andPermissions | orPermissions ) & ( S_ISUID|S_ISGID|S_ISVTX );
2182 updateAccessControls();
2191 KFilePermissionsPropsPlugin::~KFilePermissionsPropsPlugin()
2198 KFileItemList::const_iterator it = _items.constBegin();
2199 for ( ; it != _items.constEnd(); ++it ) {
2200 KFileItem *item = *it;
2201 if( !item->user().isEmpty() || !item->group().isEmpty() )
2208 void KFilePermissionsPropsPlugin::setComboContent(TQComboBox *combo, PermissionsTarget target,
2209 mode_t permissions, mode_t partial) {
2211 if (d->pmode == PermissionsOnlyLinks) {
2212 combo->insertItem(i18n(
"Link"));
2213 combo->setCurrentItem(0);
2217 mode_t tMask = permissionsMasks[target];
2219 for (textIndex = 0; standardPermissions[textIndex] != (mode_t)-1; textIndex++)
2220 if ((standardPermissions[textIndex]&tMask) == (permissions&tMask&(UniRead|UniWrite)))
2222 Q_ASSERT(standardPermissions[textIndex] != (mode_t)-1);
2224 for (
int i = 0; permissionsTexts[(int)d->pmode][i]; i++)
2225 combo->insertItem(i18n(permissionsTexts[(
int)d->pmode][i]));
2227 if (partial & tMask & ~UniExec) {
2228 combo->insertItem(i18n(
"Varying (No Change)"));
2229 combo->setCurrentItem(3);
2232 combo->setCurrentItem(textIndex);
2236 bool KFilePermissionsPropsPlugin::isIrregular(mode_t permissions,
bool isDir,
bool isLink) {
2240 mode_t p = permissions;
2241 if (p & (S_ISUID | S_ISGID))
2247 mode_t p0 = p & UniOwner;
2248 if ((p0 != 0) && (p0 != (S_IRUSR | S_IXUSR)) && (p0 != UniOwner))
2251 if ((p0 != 0) && (p0 != (S_IRGRP | S_IXGRP)) && (p0 != UniGroup))
2254 if ((p0 != 0) && (p0 != (S_IROTH | S_IXOTH)) && (p0 != UniOthers))
2262 mode_t p0 = p & UniOwner;
2263 bool usrXPossible = !p0;
2265 if ((p0 == S_IXUSR) || (p0 == (S_IWUSR | S_IXUSR)))
2267 usrXPossible =
true;
2269 else if (p0 == S_IWUSR)
2273 bool grpXPossible = !p0;
2275 if ((p0 == S_IXGRP) || (p0 == (S_IWGRP | S_IXGRP)))
2277 grpXPossible =
true;
2279 else if (p0 == S_IWGRP)
2282 grpXPossible =
true;
2285 bool othXPossible = !p0;
2287 if ((p0 == S_IXOTH) || (p0 == (S_IWOTH | S_IXOTH)))
2289 othXPossible =
true;
2291 else if (p0 == S_IWOTH)
2295 return (p & UniExec) && !(usrXPossible && grpXPossible && othXPossible);
2299 void KFilePermissionsPropsPlugin::enableAccessControls(
bool enable) {
2300 d->ownerPermCombo->setEnabled(enable);
2301 d->groupPermCombo->setEnabled(enable);
2302 d->othersPermCombo->setEnabled(enable);
2303 if (d->extraCheckbox)
2304 d->extraCheckbox->setEnabled(enable);
2305 if ( d->cbRecursive )
2306 d->cbRecursive->setEnabled(enable);
2310 void KFilePermissionsPropsPlugin::updateAccessControls() {
2311 setComboContent(d->ownerPermCombo, PermissionsOwner,
2312 permissions, d->partialPermissions);
2313 setComboContent(d->groupPermCombo, PermissionsGroup,
2314 permissions, d->partialPermissions);
2315 setComboContent(d->othersPermCombo, PermissionsOthers,
2316 permissions, d->partialPermissions);
2319 case PermissionsOnlyLinks:
2320 enableAccessControls(
false);
2322 case PermissionsOnlyFiles:
2323 enableAccessControls(d->canChangePermissions && !d->isIrregular && !d->hasExtendedACL);
2324 if (d->canChangePermissions)
2325 d->explanationLabel->setText(d->isIrregular || d->hasExtendedACL ?
2326 i18n(
"This file uses advanced permissions",
2327 "These files use advanced permissions.",
2329 if (d->partialPermissions & UniExec) {
2330 d->extraCheckbox->setTristate();
2331 d->extraCheckbox->setNoChange();
2334 d->extraCheckbox->setTristate(
false);
2335 d->extraCheckbox->setChecked(permissions & UniExec);
2338 case PermissionsOnlyDirs:
2339 enableAccessControls(d->canChangePermissions && !d->isIrregular && !d->hasExtendedACL);
2342 if ( d->cbRecursive )
2343 d->cbRecursive->setEnabled( d->canChangePermissions && !d->isIrregular );
2345 if (d->canChangePermissions)
2346 d->explanationLabel->setText(d->isIrregular || d->hasExtendedACL ?
2347 i18n(
"This folder uses advanced permissions.",
2348 "These folders use advanced permissions.",
2350 if (d->partialPermissions & S_ISVTX) {
2351 d->extraCheckbox->setTristate();
2352 d->extraCheckbox->setNoChange();
2355 d->extraCheckbox->setTristate(
false);
2356 d->extraCheckbox->setChecked(permissions & S_ISVTX);
2359 case PermissionsMixed:
2360 enableAccessControls(d->canChangePermissions && !d->isIrregular && !d->hasExtendedACL);
2361 if (d->canChangePermissions)
2362 d->explanationLabel->setText(d->isIrregular || d->hasExtendedACL ?
2363 i18n(
"These files use advanced permissions.") :
"");
2365 if (d->partialPermissions & S_ISVTX) {
2366 d->extraCheckbox->setTristate();
2367 d->extraCheckbox->setNoChange();
2370 d->extraCheckbox->setTristate(
false);
2371 d->extraCheckbox->setChecked(permissions & S_ISVTX);
2378 void KFilePermissionsPropsPlugin::getPermissionMasks(mode_t &andFilePermissions,
2379 mode_t &andDirPermissions,
2380 mode_t &orFilePermissions,
2381 mode_t &orDirPermissions) {
2382 andFilePermissions = mode_t(~UniSpecial);
2383 andDirPermissions = mode_t(~(S_ISUID|S_ISGID));
2384 orFilePermissions = 0;
2385 orDirPermissions = 0;
2389 mode_t m = standardPermissions[d->ownerPermCombo->currentItem()];
2390 if (m != (mode_t) -1) {
2391 orFilePermissions |= m & UniOwner;
2392 if ((m & UniOwner) &&
2393 ((d->pmode == PermissionsMixed) ||
2394 ((d->pmode == PermissionsOnlyFiles) && (d->extraCheckbox->state() == TQButton::NoChange))))
2395 andFilePermissions &= ~(S_IRUSR | S_IWUSR);
2397 andFilePermissions &= ~(S_IRUSR | S_IWUSR | S_IXUSR);
2398 if ((m & S_IRUSR) && (d->extraCheckbox->state() == TQButton::On))
2399 orFilePermissions |= S_IXUSR;
2402 orDirPermissions |= m & UniOwner;
2404 orDirPermissions |= S_IXUSR;
2405 andDirPermissions &= ~(S_IRUSR | S_IWUSR | S_IXUSR);
2408 m = standardPermissions[d->groupPermCombo->currentItem()];
2409 if (m != (mode_t) -1) {
2410 orFilePermissions |= m & UniGroup;
2411 if ((m & UniGroup) &&
2412 ((d->pmode == PermissionsMixed) ||
2413 ((d->pmode == PermissionsOnlyFiles) && (d->extraCheckbox->state() == TQButton::NoChange))))
2414 andFilePermissions &= ~(S_IRGRP | S_IWGRP);
2416 andFilePermissions &= ~(S_IRGRP | S_IWGRP | S_IXGRP);
2417 if ((m & S_IRGRP) && (d->extraCheckbox->state() == TQButton::On))
2418 orFilePermissions |= S_IXGRP;
2421 orDirPermissions |= m & UniGroup;
2423 orDirPermissions |= S_IXGRP;
2424 andDirPermissions &= ~(S_IRGRP | S_IWGRP | S_IXGRP);
2427 m = standardPermissions[d->othersPermCombo->currentItem()];
2428 if (m != (mode_t) -1) {
2429 orFilePermissions |= m & UniOthers;
2430 if ((m & UniOthers) &&
2431 ((d->pmode == PermissionsMixed) ||
2432 ((d->pmode == PermissionsOnlyFiles) && (d->extraCheckbox->state() == TQButton::NoChange))))
2433 andFilePermissions &= ~(S_IROTH | S_IWOTH);
2435 andFilePermissions &= ~(S_IROTH | S_IWOTH | S_IXOTH);
2436 if ((m & S_IROTH) && (d->extraCheckbox->state() == TQButton::On))
2437 orFilePermissions |= S_IXOTH;
2440 orDirPermissions |= m & UniOthers;
2442 orDirPermissions |= S_IXOTH;
2443 andDirPermissions &= ~(S_IROTH | S_IWOTH | S_IXOTH);
2446 if (((d->pmode == PermissionsMixed) || (d->pmode == PermissionsOnlyDirs)) &&
2447 (d->extraCheckbox->state() != TQButton::NoChange)) {
2448 andDirPermissions &= ~S_ISVTX;
2449 if (d->extraCheckbox->state() == TQButton::On)
2450 orDirPermissions |= S_ISVTX;
2456 mode_t orFilePermissions;
2457 mode_t orDirPermissions;
2458 mode_t andFilePermissions;
2459 mode_t andDirPermissions;
2461 if (!d->canChangePermissions)
2464 if (!d->isIrregular)
2465 getPermissionMasks(andFilePermissions,
2470 orFilePermissions = permissions;
2471 andFilePermissions = d->partialPermissions;
2472 orDirPermissions = permissions;
2473 andDirPermissions = d->partialPermissions;
2476 TQString owner, group;
2478 owner = usrEdit->text();
2480 group = grpEdit->text();
2482 group = grpCombo->currentText();
2484 if (owner == strOwner)
2485 owner = TQString::null;
2487 if (group == strGroup)
2488 group = TQString::null;
2490 bool recursive = d->cbRecursive && d->cbRecursive->isChecked();
2491 bool permissionChange =
false;
2493 KFileItemList files, dirs;
2495 for (KFileItemListIterator it(items); it.current(); ++it) {
2496 if ((*it)->isDir()) {
2498 if ((*it)->permissions() != (((*it)->permissions() & andDirPermissions) | orDirPermissions))
2499 permissionChange =
true;
2501 else if ((*it)->isFile()) {
2503 if ((*it)->permissions() != (((*it)->permissions() & andFilePermissions) | orFilePermissions))
2504 permissionChange =
true;
2508 const bool ACLChange = ( d->extendedACL !=
properties->
item()->ACL() );
2509 const bool defaultACLChange = ( d->defaultACL !=
properties->
item()->defaultACL() );
2511 if ( owner.isEmpty() && group.isEmpty() && !recursive
2512 && !permissionChange && !ACLChange && !defaultACLChange )
2516 if (files.count() > 0) {
2517 job = KIO::chmod( files, orFilePermissions, ~andFilePermissions,
2518 owner, group,
false );
2519 if ( ACLChange && d->fileSystemSupportsACLs )
2520 job->addMetaData(
"ACL_STRING", d->extendedACL.isValid()?d->extendedACL.asString():
"ACL_DELETE" );
2521 if ( defaultACLChange && d->fileSystemSupportsACLs )
2522 job->addMetaData(
"DEFAULT_ACL_STRING", d->defaultACL.isValid()?d->defaultACL.asString():
"ACL_DELETE" );
2524 connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
2525 TQT_SLOT( slotChmodResult( KIO::Job * ) ) );
2527 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
2528 qt_enter_modal(&dummy);
2529 tqApp->enter_loop();
2530 qt_leave_modal(&dummy);
2532 if (dirs.count() > 0) {
2533 job = KIO::chmod( dirs, orDirPermissions, ~andDirPermissions,
2534 owner, group, recursive );
2535 if ( ACLChange && d->fileSystemSupportsACLs )
2536 job->addMetaData(
"ACL_STRING", d->extendedACL.isValid()?d->extendedACL.asString():
"ACL_DELETE" );
2537 if ( defaultACLChange && d->fileSystemSupportsACLs )
2538 job->addMetaData(
"DEFAULT_ACL_STRING", d->defaultACL.isValid()?d->defaultACL.asString():
"ACL_DELETE" );
2540 connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
2541 TQT_SLOT( slotChmodResult( KIO::Job * ) ) );
2543 TQWidget dummy(0,0,(WFlags)(WType_Dialog|WShowModal));
2544 qt_enter_modal(&dummy);
2545 tqApp->enter_loop();
2546 qt_leave_modal(&dummy);
2550 void KFilePermissionsPropsPlugin::slotChmodResult( KIO::Job * job )
2552 kdDebug(250) <<
"KFilePermissionsPropsPlugin::slotChmodResult" << endl;
2554 job->showErrorDialog( d->m_frame );
2562 class KURLPropsPlugin::KURLPropsPluginPrivate
2565 KURLPropsPluginPrivate()
2568 ~KURLPropsPluginPrivate()
2578 d =
new KURLPropsPluginPrivate;
2579 d->m_frame =
properties->addPage(i18n(
"U&RL"));
2580 TQVBoxLayout *layout =
new TQVBoxLayout(d->m_frame, 0, KDialog::spacingHint());
2583 l =
new TQLabel( d->m_frame,
"Label_1" );
2584 l->setText( i18n(
"URL:") );
2585 layout->addWidget(l);
2588 layout->addWidget(URLEdit);
2593 if ( !f.open( IO_ReadOnly ) ) {
2598 KSimpleConfig config( path );
2599 config.setDesktopGroup();
2600 URLStr = config.readPathEntry(
"URL" );
2604 if (item && item->mimetype() ==
"media/builtin-mydocuments") {
2605 URLStr = TQString::null;
2606 KConfig xdguserconfig( TQDir::homeDirPath()+
"/.config/user-dirs.dirs" );
2607 URLEdit->
setMode(KFile::Directory);
2608 URLEdit->
setURL( xdguserconfig.readPathEntry(
"XDG_DOCUMENTS_DIR", TQDir::homeDirPath() +
"/Documents").remove(
"\"" ));
2610 else if (item && item->mimetype().startsWith(
"media/builtin-")) {
2611 URLEdit->setEnabled(
false);
2614 if ( !URLStr.isNull() ) {
2615 URLEdit->
setURL( URLStr );
2618 connect( URLEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2619 this, TQT_SIGNAL(
changed() ) );
2621 layout->addStretch (1);
2624 KURLPropsPlugin::~KURLPropsPlugin()
2634 bool KURLPropsPlugin::supports( KFileItemList _items )
2636 if ( _items.count() != 1 )
2638 KFileItem * item = _items.first();
2644 KDesktopFile config( item->url().path(),
true );
2645 return config.hasLinkType();
2653 if (item && item->mimetype() ==
"media/builtin-mydocuments") {
2654 KConfig xdgconfig(TQDir::homeDirPath()+
"/.config/user-dirs.dirs" );
2655 if (xdgconfig.isReadOnly()) {
2656 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2657 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2661 xdgconfig.writePathEntry(
"XDG_DOCUMENTS_DIR",
'"'+ URLEdit->url() +
'"',
true,
false,
false, false );
2666 else if (item && item->mimetype().startsWith(
"media/builtin-")) {
2671 if ( !f.open( IO_ReadWrite ) ) {
2672 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2673 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2678 KSimpleConfig config( path );
2679 config.setDesktopGroup();
2680 config.writeEntry(
"Type", TQString::fromLatin1(
"Link"));
2681 config.writePathEntry(
"URL", URLEdit->url() );
2684 if ( config.hasKey(
"Name") )
2686 TQString nameStr = nameFromFileName(
properties->
kurl().fileName());
2687 config.writeEntry(
"Name", nameStr );
2688 config.writeEntry(
"Name", nameStr,
true,
false,
true );
2700 class KBindingPropsPlugin::KBindingPropsPluginPrivate
2703 KBindingPropsPluginPrivate()
2706 ~KBindingPropsPluginPrivate()
2715 d =
new KBindingPropsPluginPrivate;
2716 d->m_frame =
properties->addPage(i18n(
"A&ssociation"));
2717 patternEdit =
new KLineEdit( d->m_frame,
"LineEdit_1" );
2718 commentEdit =
new KLineEdit( d->m_frame,
"LineEdit_2" );
2719 mimeEdit =
new KLineEdit( d->m_frame,
"LineEdit_3" );
2721 TQBoxLayout *mainlayout =
new TQVBoxLayout(d->m_frame, 0, KDialog::spacingHint());
2724 tmpQLabel =
new TQLabel( d->m_frame,
"Label_1" );
2725 tmpQLabel->setText( i18n(
"Pattern ( example: *.html;*.htm )") );
2726 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2727 mainlayout->addWidget(tmpQLabel, 1);
2731 patternEdit->setMaxLength( 512 );
2732 patternEdit->setMinimumSize( patternEdit->sizeHint() );
2733 patternEdit->setFixedHeight( fontHeight );
2734 mainlayout->addWidget(patternEdit, 1);
2736 tmpQLabel =
new TQLabel( d->m_frame,
"Label_2" );
2737 tmpQLabel->setText( i18n(
"Mime Type") );
2738 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2739 mainlayout->addWidget(tmpQLabel, 1);
2742 mimeEdit->setMaxLength( 256 );
2743 mimeEdit->setMinimumSize( mimeEdit->sizeHint() );
2744 mimeEdit->setFixedHeight( fontHeight );
2745 mainlayout->addWidget(mimeEdit, 1);
2747 tmpQLabel =
new TQLabel( d->m_frame,
"Label_3" );
2748 tmpQLabel->setText( i18n(
"Comment") );
2749 tmpQLabel->setMinimumSize(tmpQLabel->sizeHint());
2750 mainlayout->addWidget(tmpQLabel, 1);
2753 commentEdit->setMaxLength( 256 );
2754 commentEdit->setMinimumSize( commentEdit->sizeHint() );
2755 commentEdit->setFixedHeight( fontHeight );
2756 mainlayout->addWidget(commentEdit, 1);
2758 cbAutoEmbed =
new TQCheckBox( i18n(
"Left click previews"), d->m_frame,
"cbAutoEmbed" );
2759 mainlayout->addWidget(cbAutoEmbed, 1);
2761 mainlayout->addStretch (10);
2762 mainlayout->activate();
2764 TQFile f( _props->
kurl().path() );
2765 if ( !f.open( IO_ReadOnly ) )
2769 KSimpleConfig config( _props->
kurl().path() );
2770 config.setDesktopGroup();
2771 TQString patternStr = config.readEntry(
"Patterns" );
2772 TQString iconStr = config.readEntry(
"Icon" );
2773 TQString commentStr = config.readEntry(
"Comment" );
2774 m_sMimeStr = config.readEntry(
"MimeType" );
2776 if ( !patternStr.isEmpty() )
2777 patternEdit->setText( patternStr );
2778 if ( !commentStr.isEmpty() )
2779 commentEdit->setText( commentStr );
2780 if ( !m_sMimeStr.isEmpty() )
2781 mimeEdit->setText( m_sMimeStr );
2782 cbAutoEmbed->setTristate();
2783 if ( config.hasKey(
"X-KDE-AutoEmbed" ) )
2784 cbAutoEmbed->setChecked( config.readBoolEntry(
"X-KDE-AutoEmbed" ) );
2786 cbAutoEmbed->setNoChange();
2788 connect( patternEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2789 this, TQT_SIGNAL(
changed() ) );
2790 connect( commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2791 this, TQT_SIGNAL(
changed() ) );
2792 connect( mimeEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
2793 this, TQT_SIGNAL(
changed() ) );
2794 connect( cbAutoEmbed, TQT_SIGNAL( toggled(
bool ) ),
2795 this, TQT_SIGNAL(
changed() ) );
2798 KBindingPropsPlugin::~KBindingPropsPlugin()
2808 bool KBindingPropsPlugin::supports( KFileItemList _items )
2810 if ( _items.count() != 1 )
2812 KFileItem * item = _items.first();
2818 KDesktopFile config( item->url().path(),
true );
2819 return config.hasMimeTypeType();
2827 if ( !f.open( IO_ReadWrite ) )
2829 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
2830 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
2835 KSimpleConfig config( path );
2836 config.setDesktopGroup();
2837 config.writeEntry(
"Type", TQString::fromLatin1(
"MimeType") );
2839 config.writeEntry(
"Patterns", patternEdit->text() );
2840 config.writeEntry(
"Comment", commentEdit->text() );
2841 config.writeEntry(
"Comment",
2842 commentEdit->text(),
true,
false, true );
2843 config.writeEntry(
"MimeType", mimeEdit->text() );
2844 if ( cbAutoEmbed->state() == TQButton::NoChange )
2845 config.deleteEntry(
"X-KDE-AutoEmbed",
false );
2847 config.writeEntry(
"X-KDE-AutoEmbed", cbAutoEmbed->isChecked() );
2857 class KDevicePropsPlugin::KDevicePropsPluginPrivate
2860 KDevicePropsPluginPrivate()
2863 ~KDevicePropsPluginPrivate()
2868 TQStringList mountpointlist;
2869 TQLabel *m_freeSpaceText;
2870 TQLabel *m_freeSpaceLabel;
2871 TQProgressBar *m_freeSpaceBar;
2876 d =
new KDevicePropsPluginPrivate;
2877 d->m_frame =
properties->addPage(i18n(
"De&vice"));
2879 TQStringList devices;
2880 KMountPoint::List mountPoints = KMountPoint::possibleMountPoints();
2882 for(KMountPoint::List::ConstIterator it = mountPoints.begin();
2883 it != mountPoints.end(); ++it)
2885 KMountPoint *mp = *it;
2886 TQString mountPoint = mp->mountPoint();
2887 TQString device = mp->mountedFrom();
2888 kdDebug()<<
"mountPoint :"<<mountPoint<<
" device :"<<device<<
" mp->mountType() :"<<mp->mountType()<<endl;
2890 if ((mountPoint !=
"-") && (mountPoint !=
"none") && !mountPoint.isEmpty()
2891 && device !=
"none")
2893 devices.append( device + TQString::fromLatin1(
" (")
2894 + mountPoint + TQString::fromLatin1(
")") );
2895 m_devicelist.append(device);
2896 d->mountpointlist.append(mountPoint);
2900 TQGridLayout *layout =
new TQGridLayout( d->m_frame, 0, 2, 0,
2901 KDialog::spacingHint());
2902 layout->setColStretch(1, 1);
2905 label =
new TQLabel( d->m_frame );
2906 label->setText( devices.count() == 0 ?
2907 i18n(
"Device (/dev/fd0):") :
2909 layout->addWidget(label, 0, 0);
2911 device =
new TQComboBox(
true, d->m_frame,
"ComboBox_device" );
2912 device->insertStringList( devices );
2913 layout->addWidget(device, 0, 1);
2914 connect( device, TQT_SIGNAL( activated(
int ) ),
2915 this, TQT_SLOT( slotActivated(
int ) ) );
2917 readonly =
new TQCheckBox( d->m_frame,
"CheckBox_readonly" );
2918 readonly->setText( i18n(
"Read only") );
2919 layout->addWidget(readonly, 1, 1);
2921 label =
new TQLabel( d->m_frame );
2922 label->setText( i18n(
"File system:") );
2923 layout->addWidget(label, 2, 0);
2925 TQLabel *fileSystem =
new TQLabel( d->m_frame );
2926 layout->addWidget(fileSystem, 2, 1);
2928 label =
new TQLabel( d->m_frame );
2929 label->setText( devices.count()==0 ?
2930 i18n(
"Mount point (/mnt/floppy):") :
2931 i18n(
"Mount point:"));
2932 layout->addWidget(label, 3, 0);
2934 mountpoint =
new TQLabel( d->m_frame,
"LineEdit_mountpoint" );
2936 layout->addWidget(mountpoint, 3, 1);
2939 d->m_freeSpaceText =
new TQLabel(i18n(
"Free disk space:"), d->m_frame );
2940 layout->addWidget(d->m_freeSpaceText, 4, 0);
2942 d->m_freeSpaceLabel =
new TQLabel( d->m_frame );
2943 layout->addWidget( d->m_freeSpaceLabel, 4, 1 );
2945 d->m_freeSpaceBar =
new TQProgressBar( d->m_frame,
"freeSpaceBar" );
2946 layout->addMultiCellWidget(d->m_freeSpaceBar, 5, 5, 0, 1);
2949 d->m_freeSpaceText->hide();
2950 d->m_freeSpaceLabel->hide();
2951 d->m_freeSpaceBar->hide();
2953 KSeparator* sep =
new KSeparator( KSeparator::HLine, d->m_frame);
2954 layout->addMultiCellWidget(sep, 6, 6, 0, 1);
2957 int bsize = 66 + 2 * unmounted->style().pixelMetric(TQStyle::PM_ButtonMargin);
2958 unmounted->setFixedSize(bsize, bsize);
2959 unmounted->setIconType(KIcon::Desktop, KIcon::Device);
2960 layout->addWidget(unmounted, 7, 0);
2962 label =
new TQLabel( i18n(
"Unmounted Icon"), d->m_frame );
2963 layout->addWidget(label, 7, 1);
2965 layout->setRowStretch(8, 1);
2967 TQString path( _props->
kurl().path() );
2970 if ( !f.open( IO_ReadOnly ) )
2974 KSimpleConfig config( path );
2975 config.setDesktopGroup();
2976 TQString deviceStr = config.readEntry(
"Dev" );
2977 TQString mountPointStr = config.readEntry(
"MountPoint" );
2978 bool ro = config.readBoolEntry(
"ReadOnly",
false );
2979 TQString unmountedStr = config.readEntry(
"UnmountIcon" );
2981 fileSystem->setText( i18n(config.readEntry(
"FSType").local8Bit()) );
2983 device->setEditText( deviceStr );
2984 if ( !deviceStr.isEmpty() ) {
2986 int index = m_devicelist.findIndex(deviceStr);
2990 slotActivated( index );
2994 if ( !mountPointStr.isEmpty() )
2996 mountpoint->setText( mountPointStr );
3000 readonly->setChecked( ro );
3002 if ( unmountedStr.isEmpty() )
3003 unmountedStr = KMimeType::defaultMimeTypePtr()->KServiceType::icon();
3005 unmounted->setIcon( unmountedStr );
3007 connect( device, TQT_SIGNAL( activated(
int ) ),
3008 this, TQT_SIGNAL(
changed() ) );
3009 connect( device, TQT_SIGNAL( textChanged(
const TQString & ) ),
3010 this, TQT_SIGNAL(
changed() ) );
3011 connect( readonly, TQT_SIGNAL( toggled(
bool ) ),
3012 this, TQT_SIGNAL(
changed() ) );
3013 connect( unmounted, TQT_SIGNAL( iconChanged( TQString ) ),
3014 this, TQT_SIGNAL(
changed() ) );
3016 connect( device, TQT_SIGNAL( textChanged(
const TQString & ) ),
3017 this, TQT_SLOT( slotDeviceChanged() ) );
3020 KDevicePropsPlugin::~KDevicePropsPlugin()
3030 void KDevicePropsPlugin::updateInfo()
3033 d->m_freeSpaceText->hide();
3034 d->m_freeSpaceLabel->hide();
3035 d->m_freeSpaceBar->hide();
3037 if ( !mountpoint->text().isEmpty() )
3040 connect( job, TQT_SIGNAL( foundMountPoint(
const unsigned long&,
const unsigned long&,
3041 const unsigned long&,
const TQString& ) ),
3042 this, TQT_SLOT( slotFoundMountPoint(
const unsigned long&,
const unsigned long&,
3043 const unsigned long&,
const TQString& ) ) );
3045 job->
readDF( mountpoint->text() );
3049 void KDevicePropsPlugin::slotActivated(
int index )
3052 device->setEditText( m_devicelist[index] );
3053 mountpoint->setText( d->mountpointlist[index] );
3058 void KDevicePropsPlugin::slotDeviceChanged()
3061 int index = m_devicelist.findIndex( device->currentText() );
3063 mountpoint->setText( d->mountpointlist[index] );
3065 mountpoint->setText( TQString::null );
3070 void KDevicePropsPlugin::slotFoundMountPoint(
const unsigned long& kBSize,
3071 const unsigned long& ,
3072 const unsigned long& kBAvail,
3075 d->m_freeSpaceText->show();
3076 d->m_freeSpaceLabel->show();
3078 int percUsed = 100 - (int)(100.0 * kBAvail / kBSize);
3080 d->m_freeSpaceLabel->setText(
3082 i18n(
"Available space out of total partition size (percent used)",
"%1 out of %2 (%3% used)")
3083 .arg(KIO::convertSizeFromKB(kBAvail))
3084 .arg(KIO::convertSizeFromKB(kBSize))
3085 .arg( 100 - (
int)(100.0 * kBAvail / kBSize) ));
3087 d->m_freeSpaceBar->setProgress(percUsed, 100);
3088 d->m_freeSpaceBar->show();
3091 bool KDevicePropsPlugin::supports( KFileItemList _items )
3093 if ( _items.count() != 1 )
3095 KFileItem * item = _items.first();
3100 KDesktopFile config( item->url().path(),
true );
3101 return config.hasDeviceType();
3108 if ( !f.open( IO_ReadWrite ) )
3110 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have sufficient "
3111 "access to write to <b>%1</b>.</qt>").arg(path));
3116 KSimpleConfig config( path );
3117 config.setDesktopGroup();
3118 config.writeEntry(
"Type", TQString::fromLatin1(
"FSDevice") );
3120 config.writeEntry(
"Dev", device->currentText() );
3121 config.writeEntry(
"MountPoint", mountpoint->text() );
3123 config.writeEntry(
"UnmountIcon", unmounted->icon() );
3124 kdDebug(250) <<
"unmounted->icon() = " << unmounted->icon() << endl;
3126 config.writeEntry(
"ReadOnly", readonly->isChecked() );
3142 TQFrame *frame =
properties->addPage(i18n(
"&Application"));
3143 TQVBoxLayout *mainlayout =
new TQVBoxLayout( frame, 0, KDialog::spacingHint() );
3145 w =
new KPropertiesDesktopBase(frame);
3146 mainlayout->addWidget(w);
3148 bool bKDesktopMode = (TQCString(tqApp->name()) ==
"kdesktop");
3153 w->nameEdit->hide();
3154 w->nameLabel->hide();
3157 w->pathEdit->setMode(KFile::Directory | KFile::LocalOnly);
3158 w->pathEdit->lineEdit()->setAcceptDrops(
false);
3160 connect( w->nameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3161 connect( w->genNameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3162 connect( w->commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3163 connect( w->commandEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3164 connect( w->pathEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
this, TQT_SIGNAL(
changed() ) );
3166 connect( w->browseButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotBrowseExec() ) );
3167 connect( w->addFiletypeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotAddFiletype() ) );
3168 connect( w->delFiletypeButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotDelFiletype() ) );
3169 connect( w->advancedButton, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotAdvanced() ) );
3172 TQString path = _props->
kurl().path();
3174 if ( !f.open( IO_ReadOnly ) )
3178 KDesktopFile config( path );
3179 TQString nameStr = config.readName();
3180 TQString genNameStr = config.readGenericName();
3181 TQString commentStr = config.readComment();
3182 TQString commandStr = config.readPathEntry(
"Exec" );
3183 if (commandStr.left(12) ==
"ksystraycmd ")
3185 commandStr.remove(0, 12);
3186 m_systrayBool =
true;
3189 m_systrayBool =
false;
3191 m_origCommandStr = commandStr;
3192 TQString pathStr = config.readPathEntry(
"Path" );
3193 m_terminalBool = config.readBoolEntry(
"Terminal" );
3194 m_terminalOptionStr = config.readEntry(
"TerminalOptions" );
3195 m_suidBool = config.readBoolEntry(
"X-KDE-SubstituteUID" );
3196 m_suidUserStr = config.readEntry(
"X-KDE-Username" );
3197 if( config.hasKey(
"StartupNotify" ))
3198 m_startupBool = config.readBoolEntry(
"StartupNotify",
true );
3200 m_startupBool = config.readBoolEntry(
"X-KDE-StartupNotify",
true );
3201 m_dcopServiceType = config.readEntry(
"X-DCOP-ServiceType").lower();
3203 TQStringList mimeTypes = config.readListEntry(
"MimeType",
';' );
3205 if ( nameStr.isEmpty() || bKDesktopMode ) {
3211 if ( !bKDesktopMode )
3212 w->nameEdit->setText(nameStr);
3214 w->genNameEdit->setText( genNameStr );
3215 w->commentEdit->setText( commentStr );
3216 w->commandEdit->setText( commandStr );
3217 w->pathEdit->lineEdit()->setText( pathStr );
3218 w->filetypeList->setAllColumnsShowFocus(
true);
3220 KMimeType::Ptr defaultMimetype = KMimeType::defaultMimeTypePtr();
3221 for(TQStringList::ConstIterator it = mimeTypes.begin();
3222 it != mimeTypes.end(); )
3224 KMimeType::Ptr p = KMimeType::mimeType(*it);
3226 TQString preference;
3227 if (it != mimeTypes.end())
3230 (*it).toInt(&numeric);
3237 if (p && (p != defaultMimetype))
3239 new TQListViewItem(w->filetypeList, p->name(), p->comment(), preference);
3245 KDesktopPropsPlugin::~KDesktopPropsPlugin()
3249 void KDesktopPropsPlugin::slotSelectMimetype()
3251 TQListView *w = (TQListView*)sender();
3252 TQListViewItem *item = w->firstChild();
3255 if (item->isSelected())
3256 w->setSelected(item,
false);
3257 item = item->nextSibling();
3261 void KDesktopPropsPlugin::slotAddFiletype()
3263 KDialogBase dlg(w,
"KPropertiesMimetypes",
true,
3265 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
3267 KGuiItem okItem(i18n(
"&Add"), TQString::null ,
3268 i18n(
"Add the selected file types to\nthe list of supported file types."),
3269 i18n(
"Add the selected file types to\nthe list of supported file types."));
3270 dlg.setButtonOK(okItem);
3272 KPropertiesMimetypeBase *mw =
new KPropertiesMimetypeBase(&dlg);
3274 dlg.setMainWidget(mw);
3277 mw->listView->setRootIsDecorated(
true);
3278 mw->listView->setSelectionMode(TQListView::Extended);
3279 mw->listView->setAllColumnsShowFocus(
true);
3280 mw->listView->setFullWidth(
true);
3281 mw->listView->setMinimumSize(500,400);
3283 connect(mw->listView, TQT_SIGNAL(selectionChanged()),
3284 this, TQT_SLOT(slotSelectMimetype()));
3285 connect(mw->listView, TQT_SIGNAL(doubleClicked( TQListViewItem *,
const TQPoint &,
int )),
3286 &dlg, TQT_SLOT( slotOk()));
3288 TQMap<TQString,TQListViewItem*> majorMap;
3289 TQListViewItem *majorGroup;
3290 KMimeType::List mimetypes = KMimeType::allMimeTypes();
3291 TQValueListIterator<KMimeType::Ptr> it(mimetypes.begin());
3292 for (; it != mimetypes.end(); ++it) {
3293 TQString mimetype = (*it)->name();
3294 if (mimetype == KMimeType::defaultMimeType())
3296 int index = mimetype.find(
"/");
3297 TQString maj = mimetype.left(index);
3298 TQString min = mimetype.mid(index+1);
3300 TQMapIterator<TQString,TQListViewItem*> mit = majorMap.find( maj );
3301 if ( mit == majorMap.end() ) {
3302 majorGroup =
new TQListViewItem( mw->listView, maj );
3303 majorGroup->setExpandable(
true);
3304 mw->listView->setOpen(majorGroup,
true);
3305 majorMap.insert( maj, majorGroup );
3309 majorGroup = mit.data();
3312 TQListViewItem *item =
new TQListViewItem(majorGroup, min, (*it)->comment());
3313 item->setPixmap(0, (*it)->pixmap(KIcon::Small, IconSize(KIcon::Small)));
3315 TQMapIterator<TQString,TQListViewItem*> mit = majorMap.find(
"all" );
3316 if ( mit != majorMap.end())
3318 mw->listView->setCurrentItem(mit.data());
3319 mw->listView->ensureItemVisible(mit.data());
3323 if (dlg.exec() == KDialogBase::Accepted)
3325 KMimeType::Ptr defaultMimetype = KMimeType::defaultMimeTypePtr();
3326 TQListViewItem *majorItem = mw->listView->firstChild();
3329 TQString major = majorItem->text(0);
3331 TQListViewItem *minorItem = majorItem->firstChild();
3334 if (minorItem->isSelected())
3336 TQString mimetype = major +
"/" + minorItem->text(0);
3337 KMimeType::Ptr p = KMimeType::mimeType(mimetype);
3338 if (p && (p != defaultMimetype))
3340 mimetype = p->name();
3342 TQListViewItem *item = w->filetypeList->firstChild();
3345 if (mimetype == item->text(0))
3350 item = item->nextSibling();
3353 new TQListViewItem(w->filetypeList, p->name(), p->comment());
3358 minorItem = minorItem->nextSibling();
3361 majorItem = majorItem->nextSibling();
3367 void KDesktopPropsPlugin::slotDelFiletype()
3369 delete w->filetypeList->currentItem();
3373 void KDesktopPropsPlugin::checkCommandChanged()
3375 if (KRun::binaryName(w->commandEdit->text(),
true) !=
3376 KRun::binaryName(m_origCommandStr,
true))
3378 TQString m_origCommandStr = w->commandEdit->text();
3379 m_dcopServiceType= TQString::null;
3385 kdDebug(250) <<
"KDesktopPropsPlugin::applyChanges" << endl;
3390 if ( !f.open( IO_ReadWrite ) ) {
3391 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
3392 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
3399 checkCommandChanged();
3401 KSimpleConfig config( path );
3402 config.setDesktopGroup();
3403 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
3404 config.writeEntry(
"Comment", w->commentEdit->text() );
3405 config.writeEntry(
"Comment", w->commentEdit->text(),
true,
false, true );
3406 config.writeEntry(
"GenericName", w->genNameEdit->text() );
3407 config.writeEntry(
"GenericName", w->genNameEdit->text(),
true,
false, true );
3410 config.writePathEntry(
"Exec", w->commandEdit->text().prepend(
"ksystraycmd ") );
3412 config.writePathEntry(
"Exec", w->commandEdit->text() );
3413 config.writePathEntry(
"Path", w->pathEdit->lineEdit()->text() );
3416 TQStringList mimeTypes;
3417 for( TQListViewItem *item = w->filetypeList->firstChild();
3418 item; item = item->nextSibling() )
3420 TQString preference = item->text(2);
3421 mimeTypes.append(item->text(0));
3422 if (!preference.isEmpty())
3423 mimeTypes.append(preference);
3426 config.writeEntry(
"MimeType", mimeTypes,
';' );
3428 if ( !w->nameEdit->isHidden() ) {
3429 TQString nameStr = w->nameEdit->text();
3430 config.writeEntry(
"Name", nameStr );
3431 config.writeEntry(
"Name", nameStr,
true,
false,
true );
3434 config.writeEntry(
"Terminal", m_terminalBool);
3435 config.writeEntry(
"TerminalOptions", m_terminalOptionStr);
3436 config.writeEntry(
"X-KDE-SubstituteUID", m_suidBool);
3437 config.writeEntry(
"X-KDE-Username", m_suidUserStr);
3438 config.writeEntry(
"StartupNotify", m_startupBool);
3439 config.writeEntry(
"X-DCOP-ServiceType", m_dcopServiceType);
3443 TQString sycocaPath = KGlobal::dirs()->relativeLocation(
"apps", path);
3444 bool updateNeeded = !sycocaPath.startsWith(
"/");
3447 sycocaPath = KGlobal::dirs()->relativeLocation(
"xdgdata-apps", path);
3448 updateNeeded = !sycocaPath.startsWith(
"/");
3451 KService::rebuildKSycoca(w);
3455 void KDesktopPropsPlugin::slotBrowseExec()
3458 TQString::null, w );
3462 if ( !f.isLocalFile()) {
3463 KMessageBox::sorry(w, i18n(
"Only executables on local file systems are supported."));
3467 TQString path = f.path();
3468 KRun::shellQuote( path );
3469 w->commandEdit->setText( path );
3472 void KDesktopPropsPlugin::slotAdvanced()
3474 KDialogBase dlg(w,
"KPropertiesDesktopAdv",
true,
3475 i18n(
"Advanced Options for %1").arg(
properties->
kurl().fileName()),
3476 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok);
3477 KPropertiesDesktopAdvBase *w =
new KPropertiesDesktopAdvBase(&dlg);
3479 dlg.setMainWidget(w);
3483 checkCommandChanged();
3487 KConfigGroup confGroup( KGlobal::config(), TQString::fromLatin1(
"General") );
3488 TQString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication",
3489 TQString::fromLatin1(
"konsole"));
3491 bool terminalCloseBool =
false;
3493 if (preferredTerminal ==
"konsole")
3495 terminalCloseBool = (m_terminalOptionStr.contains(
"--noclose" ) > 0);
3496 w->terminalCloseCheck->setChecked(terminalCloseBool);
3497 m_terminalOptionStr.replace(
"--noclose",
"");
3501 w->terminalCloseCheck->hide();
3504 w->terminalCheck->setChecked(m_terminalBool);
3505 w->terminalEdit->setText(m_terminalOptionStr);
3506 w->terminalCloseCheck->setEnabled(m_terminalBool);
3507 w->terminalEdit->setEnabled(m_terminalBool);
3508 w->terminalEditLabel->setEnabled(m_terminalBool);
3510 w->suidCheck->setChecked(m_suidBool);
3511 w->suidEdit->setText(m_suidUserStr);
3512 w->suidEdit->setEnabled(m_suidBool);
3513 w->suidEditLabel->setEnabled(m_suidBool);
3515 w->startupInfoCheck->setChecked(m_startupBool);
3516 w->systrayCheck->setChecked(m_systrayBool);
3518 if (m_dcopServiceType ==
"unique")
3519 w->dcopCombo->setCurrentItem(2);
3520 else if (m_dcopServiceType ==
"multi")
3521 w->dcopCombo->setCurrentItem(1);
3522 else if (m_dcopServiceType ==
"wait")
3523 w->dcopCombo->setCurrentItem(3);
3525 w->dcopCombo->setCurrentItem(0);
3528 KCompletion *kcom =
new KCompletion;
3529 kcom->setOrder(KCompletion::Sorted);
3531 int i, maxEntries = 1000;
3533 for (i=0; ((pw = getpwent()) != 0L) && (i < maxEntries); i++)
3534 kcom->addItem(TQString::fromLatin1(pw->pw_name));
3538 w->suidEdit->setCompletionObject(kcom,
true);
3539 w->suidEdit->setAutoDeleteCompletionObject(
true );
3540 w->suidEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
3547 connect( w->terminalEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3548 this, TQT_SIGNAL(
changed() ) );
3549 connect( w->terminalCloseCheck, TQT_SIGNAL( toggled(
bool ) ),
3550 this, TQT_SIGNAL(
changed() ) );
3551 connect( w->terminalCheck, TQT_SIGNAL( toggled(
bool ) ),
3552 this, TQT_SIGNAL(
changed() ) );
3553 connect( w->suidCheck, TQT_SIGNAL( toggled(
bool ) ),
3554 this, TQT_SIGNAL(
changed() ) );
3555 connect( w->suidEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3556 this, TQT_SIGNAL(
changed() ) );
3557 connect( w->startupInfoCheck, TQT_SIGNAL( toggled(
bool ) ),
3558 this, TQT_SIGNAL(
changed() ) );
3559 connect( w->systrayCheck, TQT_SIGNAL( toggled(
bool ) ),
3560 this, TQT_SIGNAL(
changed() ) );
3561 connect( w->dcopCombo, TQT_SIGNAL( highlighted(
int ) ),
3562 this, TQT_SIGNAL(
changed() ) );
3564 if ( dlg.exec() == TQDialog::Accepted )
3566 m_terminalOptionStr = w->terminalEdit->text().stripWhiteSpace();
3567 m_terminalBool = w->terminalCheck->isChecked();
3568 m_suidBool = w->suidCheck->isChecked();
3569 m_suidUserStr = w->suidEdit->text().stripWhiteSpace();
3570 m_startupBool = w->startupInfoCheck->isChecked();
3571 m_systrayBool = w->systrayCheck->isChecked();
3573 if (w->terminalCloseCheck->isChecked())
3575 m_terminalOptionStr.append(
" --noclose");
3578 switch(w->dcopCombo->currentItem())
3580 case 1: m_dcopServiceType =
"multi";
break;
3581 case 2: m_dcopServiceType =
"unique";
break;
3582 case 3: m_dcopServiceType =
"wait";
break;
3583 default: m_dcopServiceType =
"none";
break;
3588 bool KDesktopPropsPlugin::supports( KFileItemList _items )
3590 if ( _items.count() != 1 )
3592 KFileItem * item = _items.first();
3597 KDesktopFile config( item->url().path(),
true );
3598 return config.hasApplicationType() && kapp->authorize(
"run_desktop_files") && kapp->authorize(
"shell_access");
3601 void KPropertiesDialog::virtual_hook(
int id,
void* data )
3602 { KDialogBase::virtual_hook(
id, data ); }
3604 void KPropsDlgPlugin::virtual_hook(
int,
void* )
3616 class KExecPropsPlugin::KExecPropsPluginPrivate
3619 KExecPropsPluginPrivate()
3622 ~KExecPropsPluginPrivate()
3627 TQCheckBox *nocloseonexitCheck;
3633 d =
new KExecPropsPluginPrivate;
3634 d->m_frame =
properties->addPage(i18n(
"E&xecute"));
3635 TQVBoxLayout * mainlayout =
new TQVBoxLayout( d->m_frame, 0,
3636 KDialog::spacingHint());
3641 l =
new TQLabel( i18n(
"Comman&d:" ), d->m_frame );
3642 mainlayout->addWidget(l);
3644 TQHBoxLayout * hlayout;
3645 hlayout =
new TQHBoxLayout(KDialog::spacingHint());
3646 mainlayout->addLayout(hlayout);
3648 execEdit =
new KLineEdit( d->m_frame );
3649 TQWhatsThis::add(execEdit,i18n(
3650 "Following the command, you can have several place holders which will be replaced "
3651 "with the actual values when the actual program is run:\n"
3652 "%f - a single file name\n"
3653 "%F - a list of files; use for applications that can open several local files at once\n"
3654 "%u - a single URL\n"
3655 "%U - a list of URLs\n"
3656 "%d - the folder of the file to open\n"
3657 "%D - a list of folders\n"
3659 "%m - the mini-icon\n"
3660 "%c - the caption"));
3661 hlayout->addWidget(execEdit, 1);
3663 l->setBuddy( execEdit );
3665 execBrowse =
new TQPushButton( d->m_frame );
3666 execBrowse->setText( i18n(
"&Browse...") );
3667 hlayout->addWidget(execBrowse);
3670 TQGroupBox* tmpQGroupBox;
3671 tmpQGroupBox =
new TQGroupBox( i18n(
"Panel Embedding"), d->m_frame );
3672 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3674 mainlayout->addWidget(tmpQGroupBox);
3676 TQGridLayout *grid =
new TQGridLayout(tmpQGroupBox->layout(), 2, 2);
3677 grid->setSpacing( KDialog::spacingHint() );
3678 grid->setColStretch(1, 1);
3680 l =
new TQLabel( i18n(
"&Execute on click:" ), tmpQGroupBox );
3681 grid->addWidget(l, 0, 0);
3683 swallowExecEdit =
new KLineEdit( tmpQGroupBox );
3684 grid->addWidget(swallowExecEdit, 0, 1);
3686 l->setBuddy( swallowExecEdit );
3688 l =
new TQLabel( i18n(
"&Window title:" ), tmpQGroupBox );
3689 grid->addWidget(l, 1, 0);
3691 swallowTitleEdit =
new KLineEdit( tmpQGroupBox );
3692 grid->addWidget(swallowTitleEdit, 1, 1);
3694 l->setBuddy( swallowTitleEdit );
3698 tmpQGroupBox =
new TQGroupBox( d->m_frame );
3699 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3701 mainlayout->addWidget(tmpQGroupBox);
3703 grid =
new TQGridLayout(tmpQGroupBox->layout(), 3, 2);
3704 grid->setSpacing( KDialog::spacingHint() );
3705 grid->setColStretch(1, 1);
3707 terminalCheck =
new TQCheckBox( tmpQGroupBox );
3708 terminalCheck->setText( i18n(
"&Run in terminal") );
3709 grid->addMultiCellWidget(terminalCheck, 0, 0, 0, 1);
3713 KConfigGroup confGroup( KGlobal::config(), TQString::fromLatin1(
"General") );
3714 TQString preferredTerminal = confGroup.readPathEntry(
"TerminalApplication",
3715 TQString::fromLatin1(
"konsole"));
3718 d->nocloseonexitCheck = 0L;
3719 if (preferredTerminal ==
"konsole")
3722 d->nocloseonexitCheck =
new TQCheckBox( tmpQGroupBox );
3723 d->nocloseonexitCheck->setText( i18n(
"Do not &close when command exits") );
3724 grid->addMultiCellWidget(d->nocloseonexitCheck, 1, 1, 0, 1);
3727 terminalLabel =
new TQLabel( i18n(
"&Terminal options:" ), tmpQGroupBox );
3728 grid->addWidget(terminalLabel, posOptions, 0);
3730 terminalEdit =
new KLineEdit( tmpQGroupBox );
3731 grid->addWidget(terminalEdit, posOptions, 1);
3733 terminalLabel->setBuddy( terminalEdit );
3737 tmpQGroupBox =
new TQGroupBox( d->m_frame );
3738 tmpQGroupBox->setColumnLayout( 0, Qt::Horizontal );
3740 mainlayout->addWidget(tmpQGroupBox);
3742 grid =
new TQGridLayout(tmpQGroupBox->layout(), 2, 2);
3743 grid->setSpacing(KDialog::spacingHint());
3744 grid->setColStretch(1, 1);
3746 suidCheck =
new TQCheckBox(tmpQGroupBox);
3747 suidCheck->setText(i18n(
"Ru&n as a different user"));
3748 grid->addMultiCellWidget(suidCheck, 0, 0, 0, 1);
3750 suidLabel =
new TQLabel(i18n(
"&Username:" ), tmpQGroupBox);
3751 grid->addWidget(suidLabel, 1, 0);
3753 suidEdit =
new KLineEdit(tmpQGroupBox);
3754 grid->addWidget(suidEdit, 1, 1);
3756 suidLabel->setBuddy( suidEdit );
3758 mainlayout->addStretch(1);
3761 TQString path = _props->
kurl().path();
3763 if ( !f.open( IO_ReadOnly ) )
3767 KSimpleConfig config( path );
3768 config.setDollarExpansion(
false );
3769 config.setDesktopGroup();
3770 execStr = config.readPathEntry(
"Exec" );
3771 swallowExecStr = config.readPathEntry(
"SwallowExec" );
3772 swallowTitleStr = config.readEntry(
"SwallowTitle" );
3773 termBool = config.readBoolEntry(
"Terminal" );
3774 termOptionsStr = config.readEntry(
"TerminalOptions" );
3775 suidBool = config.readBoolEntry(
"X-KDE-SubstituteUID" );
3776 suidUserStr = config.readEntry(
"X-KDE-Username" );
3778 if ( !swallowExecStr.isNull() )
3779 swallowExecEdit->setText( swallowExecStr );
3780 if ( !swallowTitleStr.isNull() )
3781 swallowTitleEdit->setText( swallowTitleStr );
3783 if ( !execStr.isNull() )
3784 execEdit->setText( execStr );
3786 if ( d->nocloseonexitCheck )
3788 d->nocloseonexitCheck->setChecked( (termOptionsStr.contains(
"--noclose" ) > 0) );
3789 termOptionsStr.replace(
"--noclose",
"");
3791 if ( !termOptionsStr.isNull() )
3792 terminalEdit->setText( termOptionsStr );
3794 terminalCheck->setChecked( termBool );
3795 enableCheckedEdit();
3797 suidCheck->setChecked( suidBool );
3798 suidEdit->setText( suidUserStr );
3802 KCompletion *kcom =
new KCompletion;
3803 kcom->setOrder(KCompletion::Sorted);
3805 int i, maxEntries = 1000;
3807 for (i=0; ((pw = getpwent()) != 0L) && (i < maxEntries); i++)
3808 kcom->addItem(TQString::fromLatin1(pw->pw_name));
3812 suidEdit->setCompletionObject(kcom,
true);
3813 suidEdit->setAutoDeleteCompletionObject(
true );
3814 suidEdit->setCompletionMode(KGlobalSettings::CompletionAuto);
3821 connect( swallowExecEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3822 this, TQT_SIGNAL(
changed() ) );
3823 connect( swallowTitleEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3824 this, TQT_SIGNAL(
changed() ) );
3825 connect( execEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3826 this, TQT_SIGNAL(
changed() ) );
3827 connect( terminalEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3828 this, TQT_SIGNAL(
changed() ) );
3829 if (d->nocloseonexitCheck)
3830 connect( d->nocloseonexitCheck, TQT_SIGNAL( toggled(
bool ) ),
3831 this, TQT_SIGNAL(
changed() ) );
3832 connect( terminalCheck, TQT_SIGNAL( toggled(
bool ) ),
3833 this, TQT_SIGNAL(
changed() ) );
3834 connect( suidCheck, TQT_SIGNAL( toggled(
bool ) ),
3835 this, TQT_SIGNAL(
changed() ) );
3836 connect( suidEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
3837 this, TQT_SIGNAL(
changed() ) );
3839 connect( execBrowse, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( slotBrowseExec() ) );
3840 connect( terminalCheck, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( enableCheckedEdit() ) );
3841 connect( suidCheck, TQT_SIGNAL( clicked() ),
this, TQT_SLOT( enableSuidEdit() ) );
3845 KExecPropsPlugin::~KExecPropsPlugin()
3850 void KExecPropsPlugin::enableCheckedEdit()
3852 bool checked = terminalCheck->isChecked();
3853 terminalLabel->setEnabled( checked );
3854 if (d->nocloseonexitCheck)
3855 d->nocloseonexitCheck->setEnabled( checked );
3856 terminalEdit->setEnabled( checked );
3859 void KExecPropsPlugin::enableSuidEdit()
3861 bool checked = suidCheck->isChecked();
3862 suidLabel->setEnabled( checked );
3863 suidEdit->setEnabled( checked );
3866 bool KExecPropsPlugin::supports( KFileItemList _items )
3868 if ( _items.count() != 1 )
3870 KFileItem * item = _items.first();
3875 KDesktopFile config( item->url().path(),
true );
3876 return config.hasApplicationType() && kapp->authorize(
"run_desktop_files") && kapp->authorize(
"shell_access");
3881 kdDebug(250) <<
"KExecPropsPlugin::applyChanges" << endl;
3886 if ( !f.open( IO_ReadWrite ) ) {
3887 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not have "
3888 "sufficient access to write to <b>%1</b>.</qt>").arg(path));
3893 KSimpleConfig config( path );
3894 config.setDesktopGroup();
3895 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
3896 config.writePathEntry(
"Exec", execEdit->text() );
3897 config.writePathEntry(
"SwallowExec", swallowExecEdit->text() );
3898 config.writeEntry(
"SwallowTitle", swallowTitleEdit->text() );
3899 config.writeEntry(
"Terminal", terminalCheck->isChecked() );
3900 TQString temp = terminalEdit->text();
3901 if (d->nocloseonexitCheck )
3902 if ( d->nocloseonexitCheck->isChecked() )
3903 temp += TQString::fromLatin1(
"--noclose ");
3904 temp = temp.stripWhiteSpace();
3905 config.writeEntry(
"TerminalOptions", temp );
3906 config.writeEntry(
"X-KDE-SubstituteUID", suidCheck->isChecked() );
3907 config.writeEntry(
"X-KDE-Username", suidEdit->text() );
3911 void KExecPropsPlugin::slotBrowseExec()
3914 TQString::null, d->m_frame );
3918 if ( !f.isLocalFile()) {
3919 KMessageBox::sorry(d->m_frame, i18n(
"Only executables on local file systems are supported."));
3923 TQString path = f.path();
3924 KRun::shellQuote( path );
3925 execEdit->setText( path );
3928 class KApplicationPropsPlugin::KApplicationPropsPluginPrivate
3931 KApplicationPropsPluginPrivate()
3933 m_kdesktopMode = TQCString(tqApp->name()) ==
"kdesktop";
3935 ~KApplicationPropsPluginPrivate()
3940 bool m_kdesktopMode;
3946 d =
new KApplicationPropsPluginPrivate;
3947 d->m_frame =
properties->addPage(i18n(
"&Application"));
3948 TQVBoxLayout *toplayout =
new TQVBoxLayout( d->m_frame, 0, KDialog::spacingHint());
3953 addExtensionButton =
new TQPushButton( TQString::null, d->m_frame );
3954 iconSet = SmallIconSet(
"back" );
3955 addExtensionButton->setIconSet( iconSet );
3956 pixMap = iconSet.pixmap( TQIconSet::Small, TQIconSet::Normal );
3957 addExtensionButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
3958 connect( addExtensionButton, TQT_SIGNAL( clicked() ),
3959 TQT_SLOT( slotAddExtension() ) );
3961 delExtensionButton =
new TQPushButton( TQString::null, d->m_frame );
3962 iconSet = SmallIconSet(
"forward" );
3963 delExtensionButton->setIconSet( iconSet );
3964 delExtensionButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
3965 connect( delExtensionButton, TQT_SIGNAL( clicked() ),
3966 TQT_SLOT( slotDelExtension() ) );
3970 TQGridLayout *grid =
new TQGridLayout(2, 2);
3971 grid->setColStretch(1, 1);
3972 toplayout->addLayout(TQT_TQLAYOUT(grid));
3974 if ( d->m_kdesktopMode )
3981 l =
new TQLabel(i18n(
"Name:"), d->m_frame,
"Label_4" );
3982 grid->addWidget(l, 0, 0);
3984 nameEdit =
new KLineEdit( d->m_frame,
"LineEdit_3" );
3985 grid->addWidget(nameEdit, 0, 1);
3988 l =
new TQLabel(i18n(
"Description:"), d->m_frame,
"Label_5" );
3989 grid->addWidget(l, 1, 0);
3991 genNameEdit =
new KLineEdit( d->m_frame,
"LineEdit_4" );
3992 grid->addWidget(genNameEdit, 1, 1);
3994 l =
new TQLabel(i18n(
"Comment:"), d->m_frame,
"Label_3" );
3995 grid->addWidget(l, 2, 0);
3997 commentEdit =
new KLineEdit( d->m_frame,
"LineEdit_2" );
3998 grid->addWidget(commentEdit, 2, 1);
4000 l =
new TQLabel(i18n(
"File types:"), d->m_frame);
4001 toplayout->addWidget(l, 0, AlignLeft);
4003 grid =
new TQGridLayout(4, 3);
4004 grid->setColStretch(0, 1);
4005 grid->setColStretch(2, 1);
4006 grid->setRowStretch( 0, 1 );
4007 grid->setRowStretch( 3, 1 );
4008 toplayout->addLayout(TQT_TQLAYOUT(grid), 2);
4010 extensionsList =
new TQListBox( d->m_frame );
4011 extensionsList->setSelectionMode( TQListBox::Extended );
4012 grid->addMultiCellWidget(extensionsList, 0, 3, 0, 0);
4014 grid->addWidget(addExtensionButton, 1, 1);
4015 grid->addWidget(delExtensionButton, 2, 1);
4017 availableExtensionsList =
new TQListBox( d->m_frame );
4018 availableExtensionsList->setSelectionMode( TQListBox::Extended );
4019 grid->addMultiCellWidget(availableExtensionsList, 0, 3, 2, 2);
4023 if ( !f.open( IO_ReadOnly ) )
4027 KDesktopFile config( path );
4028 TQString commentStr = config.readComment();
4029 TQString genNameStr = config.readGenericName();
4031 TQStringList selectedTypes = config.readListEntry(
"ServiceTypes" );
4033 selectedTypes += config.readListEntry(
"MimeType",
';' );
4035 TQString nameStr = config.readName();
4036 if ( nameStr.isEmpty() || d->m_kdesktopMode ) {
4043 commentEdit->setText( commentStr );
4044 genNameEdit->setText( genNameStr );
4046 nameEdit->setText( nameStr );
4048 selectedTypes.sort();
4049 TQStringList::Iterator sit = selectedTypes.begin();
4050 for( ; sit != selectedTypes.end(); ++sit ) {
4051 if ( !((*sit).isEmpty()) )
4052 extensionsList->insertItem( *sit );
4055 KMimeType::List mimeTypes = KMimeType::allMimeTypes();
4056 TQValueListIterator<KMimeType::Ptr> it2 = mimeTypes.begin();
4057 for ( ; it2 != mimeTypes.end(); ++it2 )
4058 addMimeType ( (*it2)->name() );
4062 connect( extensionsList, TQT_SIGNAL( highlighted(
int ) ),
4063 this, TQT_SLOT( updateButton() ) );
4064 connect( availableExtensionsList, TQT_SIGNAL( highlighted(
int ) ),
4065 this, TQT_SLOT( updateButton() ) );
4067 connect( addExtensionButton, TQT_SIGNAL( clicked() ),
4068 this, TQT_SIGNAL(
changed() ) );
4069 connect( delExtensionButton, TQT_SIGNAL( clicked() ),
4070 this, TQT_SIGNAL(
changed() ) );
4072 connect( nameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4073 this, TQT_SIGNAL(
changed() ) );
4074 connect( commentEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4075 this, TQT_SIGNAL(
changed() ) );
4076 connect( genNameEdit, TQT_SIGNAL( textChanged(
const TQString & ) ),
4077 this, TQT_SIGNAL(
changed() ) );
4078 connect( availableExtensionsList, TQT_SIGNAL( selected(
int ) ),
4079 this, TQT_SIGNAL(
changed() ) );
4080 connect( extensionsList, TQT_SIGNAL( selected(
int ) ),
4081 this, TQT_SIGNAL(
changed() ) );
4084 KApplicationPropsPlugin::~KApplicationPropsPlugin()
4094 void KApplicationPropsPlugin::updateButton()
4096 addExtensionButton->setEnabled(availableExtensionsList->currentItem()>-1);
4097 delExtensionButton->setEnabled(extensionsList->currentItem()>-1);
4100 void KApplicationPropsPlugin::addMimeType(
const TQString & name )
4106 for ( uint i = 0; i < extensionsList->count(); i++ )
4107 if ( extensionsList->text( i ) == name )
4112 availableExtensionsList->insertItem( name );
4113 availableExtensionsList->sort();
4117 bool KApplicationPropsPlugin::supports( KFileItemList _items )
4120 return KExecPropsPlugin::supports( _items );
4129 if ( !f.open( IO_ReadWrite ) ) {
4130 KMessageBox::sorry( 0, i18n(
"<qt>Could not save properties. You do not "
4131 "have sufficient access to write to <b>%1</b>.</qt>").arg(path));
4136 KSimpleConfig config( path );
4137 config.setDesktopGroup();
4138 config.writeEntry(
"Type", TQString::fromLatin1(
"Application"));
4139 config.writeEntry(
"Comment", commentEdit->text() );
4140 config.writeEntry(
"Comment", commentEdit->text(),
true,
false, true );
4141 config.writeEntry(
"GenericName", genNameEdit->text() );
4142 config.writeEntry(
"GenericName", genNameEdit->text(),
true,
false, true );
4144 TQStringList selectedTypes;
4145 for ( uint i = 0; i < extensionsList->count(); i++ )
4146 selectedTypes.append( extensionsList->text( i ) );
4148 config.writeEntry(
"MimeType", selectedTypes,
';' );
4149 config.writeEntry(
"ServiceTypes",
"" );
4152 TQString nameStr = nameEdit ? nameEdit->text() : TQString::null;
4153 if ( nameStr.isEmpty() )
4156 config.writeEntry(
"Name", nameStr );
4157 config.writeEntry(
"Name", nameStr,
true,
false,
true );
4162 void KApplicationPropsPlugin::slotAddExtension()
4164 TQListBoxItem *item = availableExtensionsList->firstItem();
4165 TQListBoxItem *nextItem;
4169 nextItem = item->next();
4171 if ( item->isSelected() )
4173 extensionsList->insertItem( item->text() );
4174 availableExtensionsList->removeItem( availableExtensionsList->index( item ) );
4180 extensionsList->sort();
4184 void KApplicationPropsPlugin::slotDelExtension()
4186 TQListBoxItem *item = extensionsList->firstItem();
4187 TQListBoxItem *nextItem;
4191 nextItem = item->next();
4193 if ( item->isSelected() )
4195 availableExtensionsList->insertItem( item->text() );
4196 extensionsList->removeItem( extensionsList->index( item ) );
4202 availableExtensionsList->sort();
4208 #include "kpropertiesdialog.moc"