Browse Source

Fixed service lookup in KOpenWithDlg. Default is now to lookup by

desktop path and not by name, to avoid returning the wrong service when
two or more .desktop files where using the same "Name" field.
This resolves bug 2734 (together with the changes made in applications/kcmautostart)

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/1/head
Michele Calgaro 1 year ago
parent
commit
bcdfbb95e9
3 changed files with 41 additions and 30 deletions
  1. 32
    23
      tdeio/tdefile/kopenwith.cpp
  2. 2
    2
      tdeio/tdefile/kopenwith.h
  3. 7
    5
      tdeio/tdefile/kopenwith_p.h

+ 32
- 23
tdeio/tdefile/kopenwith.cpp View File

@@ -70,32 +70,36 @@
70 70
 // ----------------------------------------------------------------------
71 71
 
72 72
 KAppTreeListItem::KAppTreeListItem( TDEListView* parent, const TQString & name,
73
-                                    const TQPixmap& pixmap, bool parse, bool dir, const TQString &p, const TQString &c )
73
+                                    const TQPixmap& pixmap, bool parse, bool dir,
74
+                                    const TQString &p, const TQString &c, const TQString &dp )
74 75
     : TQListViewItem( parent, name )
75 76
 {
76
-    init(pixmap, parse, dir, p, c);
77
+    init(pixmap, parse, dir, p, c, dp);
77 78
 }
78 79
 
79 80
 
80 81
 // ----------------------------------------------------------------------
81 82
 
82 83
 KAppTreeListItem::KAppTreeListItem( TQListViewItem* parent, const TQString & name,
83
-                                    const TQPixmap& pixmap, bool parse, bool dir, const TQString &p, const TQString &c )
84
+                                    const TQPixmap& pixmap, bool parse, bool dir,
85
+                                    const TQString &p, const TQString &c, const TQString &dp )
84 86
     : TQListViewItem( parent, name )
85 87
 {
86
-    init(pixmap, parse, dir, p, c);
88
+    init(pixmap, parse, dir, p, c, dp);
87 89
 }
88 90
 
89 91
 
90 92
 // ----------------------------------------------------------------------
91 93
 
92
-void KAppTreeListItem::init(const TQPixmap& pixmap, bool parse, bool dir, const TQString &_path, const TQString &_exec)
94
+void KAppTreeListItem::init(const TQPixmap& pixmap, bool parse, bool dir, 
95
+                            const TQString &_path, const TQString &_exec, const TQString &_desktopPath)
93 96
 {
94 97
     setPixmap(0, pixmap);
95 98
     parsed = parse;
96 99
     directory = dir;
97 100
     path = _path; // relative path
98
-    exec = _exec;
101
+    exec = _exec; // executable command
102
+    desktopPath = _desktopPath;  // .desktop file path
99 103
 }
100 104
 
101 105
 
@@ -193,10 +197,7 @@ void TDEApplicationTree::addDesktopGroup( const TQString &relPath, KAppTreeListI
193 197
    for( KServiceGroup::List::ConstIterator it = list.begin();
194 198
        it != list.end(); it++)
195 199
    {
196
-      TQString icon;
197
-      TQString text;
198
-      TQString relPath;
199
-      TQString exec;
200
+      TQString icon, text, relPath, exec, desktopPath;
200 201
       bool isDir = false;
201 202
       KSycocaEntry *p = (*it);
202 203
       if (p->isType(KST_KService))
@@ -209,6 +210,7 @@ void TDEApplicationTree::addDesktopGroup( const TQString &relPath, KAppTreeListI
209 210
          icon = service->icon();
210 211
          text = service->name();
211 212
          exec = service->exec();
213
+         desktopPath = service->desktopEntryPath();
212 214
       }
213 215
       else if (p->isType(KST_KServiceGroup))
214 216
       {
@@ -229,13 +231,13 @@ void TDEApplicationTree::addDesktopGroup( const TQString &relPath, KAppTreeListI
229 231
       }
230 232
 
231 233
       TQPixmap pixmap = appIcon( icon );
232
-
234
+      
233 235
       if (item)
234 236
          newItem = new KAppTreeListItem( item, text, pixmap, false, isDir,
235
-                                         relPath, exec );
237
+                                         relPath, exec, desktopPath );
236 238
       else
237 239
          newItem = new KAppTreeListItem( this, text, pixmap, false, isDir,
238
-                                         relPath, exec );
240
+                                         relPath, exec, desktopPath );
239 241
       if (isDir)
240 242
          newItem->setExpandable( true );
241 243
    }
@@ -255,7 +257,7 @@ void TDEApplicationTree::slotItemHighlighted(TQListViewItem* i)
255 257
     currentitem = item;
256 258
 
257 259
     if( (!item->directory ) && (!item->exec.isEmpty()) )
258
-        emit highlighted( item->text(0), item->exec );
260
+        emit highlighted( item->text(0), item->exec, item->desktopPath );
259 261
 }
260 262
 
261 263
 
@@ -272,7 +274,7 @@ void TDEApplicationTree::slotSelectionChanged(TQListViewItem* i)
272 274
     currentitem = item;
273 275
 
274 276
     if( ( !item->directory ) && (!item->exec.isEmpty() ) )
275
-        emit selected( item->text(0), item->exec );
277
+        emit selected( item->text(0), item->exec, item->desktopPath );
276 278
 }
277 279
 
278 280
 // ----------------------------------------------------------------------
@@ -350,7 +352,7 @@ KOpenWithDlg::KOpenWithDlg( const TQString &serviceType, const TQString& value,
350 352
                             TQWidget *parent)
351 353
              :TQDialog( parent, "openwith", true )
352 354
 {
353
-    setCaption(i18n("Choose Application for %1").arg(serviceType));
355
+   setCaption(i18n("Choose Application for %1").arg(serviceType));
354 356
   TQString text = i18n("<qt>Select the program for the file type: <b>%1</b>. "
355 357
                       "If the program is not listed, enter the name or click "
356 358
                       "the browse button.</qt>").arg(serviceType);
@@ -459,10 +461,10 @@ void KOpenWithDlg::init( const TQString& _text, const TQString& _value )
459 461
   m_pTree = new TDEApplicationTree( this );
460 462
   topLayout->addWidget(m_pTree);
461 463
 
462
-  connect( m_pTree, TQT_SIGNAL( selected( const TQString&, const TQString& ) ),
463
-           TQT_SLOT( slotSelected( const TQString&, const TQString& ) ) );
464
-  connect( m_pTree, TQT_SIGNAL( highlighted( const TQString&, const TQString& ) ),
465
-           TQT_SLOT( slotHighlighted( const TQString&, const TQString& ) ) );
464
+  connect( m_pTree, TQT_SIGNAL( selected( const TQString&, const TQString&, const TQString& ) ),
465
+           TQT_SLOT( slotSelected( const TQString&, const TQString&, const TQString& ) ) );
466
+  connect( m_pTree, TQT_SIGNAL( highlighted( const TQString&, const TQString&, const TQString& ) ),
467
+           TQT_SLOT( slotHighlighted( const TQString&, const TQString&, const TQString& ) ) );
466 468
   connect( m_pTree, TQT_SIGNAL( doubleClicked(TQListViewItem*) ),
467 469
            TQT_SLOT( slotDbClick() ) );
468 470
 
@@ -543,7 +545,7 @@ void KOpenWithDlg::slotClear()
543 545
 
544 546
 // ----------------------------------------------------------------------
545 547
 
546
-void KOpenWithDlg::slotSelected( const TQString& /*_name*/, const TQString& _exec )
548
+void KOpenWithDlg::slotSelected( const TQString& /*_name*/, const TQString& _exec, const TQString& /*_desktopPath*/ )
547 549
 {
548 550
     kdDebug(250)<<"KOpenWithDlg::slotSelected"<<endl;
549 551
     KService::Ptr pService = d->curService;
@@ -554,11 +556,18 @@ void KOpenWithDlg::slotSelected( const TQString& /*_name*/, const TQString& _exe
554 556
 
555 557
 // ----------------------------------------------------------------------
556 558
 
557
-void KOpenWithDlg::slotHighlighted( const TQString& _name, const TQString& )
559
+void KOpenWithDlg::slotHighlighted( const TQString& _name, const TQString& _exec, const TQString& _desktopPath )
558 560
 {
559 561
     kdDebug(250)<<"KOpenWithDlg::slotHighlighted"<<endl;
560 562
     qName = _name;
561
-    d->curService = KService::serviceByName( qName );
563
+    // Look up by desktop path first, to avoid returning wrong results in case multiple .desktop files
564
+    // contain the same name for different services (such as Konsole)
565
+    // Try by name only if first search fails (this should never happen normally)
566
+    d->curService = KService::serviceByDesktopPath( _desktopPath )
567
+    if (!d->curService)
568
+    { 
569
+    	d->curService = KService::serviceByName( qName );
570
+    }
562 571
     if (!m_terminaldirty)
563 572
     {
564 573
         // ### indicate that default value was restored

+ 2
- 2
tdeio/tdefile/kopenwith.h View File

@@ -129,8 +129,8 @@ public slots:
129 129
     * The slot for clearing the edit widget
130 130
     */
131 131
     void slotClear();
132
-    void slotSelected( const TQString&_name, const TQString& _exec );
133
-    void slotHighlighted( const TQString& _name, const TQString& _exec );
132
+    void slotSelected( const TQString&_name, const TQString& _exec, const TQString& _desktopPath );
133
+    void slotHighlighted( const TQString& _name, const TQString& _exec, const TQString& _desktopPath );
134 134
     void slotTextChanged();
135 135
     void slotTerminalToggled(bool);
136 136
     void slotDbClick();

+ 7
- 5
tdeio/tdefile/kopenwith_p.h View File

@@ -43,18 +43,20 @@ class KAppTreeListItem : public TQListViewItem
43 43
     bool directory;
44 44
     TQString path;
45 45
     TQString exec;
46
+    TQString desktopPath;
46 47
 
47 48
 protected:
48 49
 	int compare(TQListViewItem *i, int col, bool ascending ) const;
49 50
     TQString key(int column, bool ascending) const;
50 51
 
51
-    void init(const TQPixmap& pixmap, bool parse, bool dir, const TQString &_path, const TQString &exec);
52
+    void init(const TQPixmap& pixmap, bool parse, bool dir, 
53
+    					const TQString &_path, const TQString &exec, const TQString &_desktopPath);
52 54
 
53 55
 public:
54 56
     KAppTreeListItem( TDEListView* parent, const TQString & name, const TQPixmap& pixmap,
55
-                      bool parse, bool dir, const TQString &p, const TQString &c );
57
+                      bool parse, bool dir, const TQString &p, const TQString &c, const TQString &dp );
56 58
     KAppTreeListItem( TQListViewItem* parent, const TQString & name, const TQPixmap& pixmap,
57
-                      bool parse, bool dir, const TQString &p, const TQString &c );
59
+                      bool parse, bool dir, const TQString &p, const TQString &c, const TQString &dp );
58 60
     bool isDirectory();
59 61
 
60 62
 protected:
@@ -92,8 +94,8 @@ public slots:
92 94
     void slotSelectionChanged(TQListViewItem* i);
93 95
 
94 96
 signals:
95
-    void selected( const TQString& _name, const TQString& _exec );
96
-    void highlighted( const TQString& _name, const  TQString& _exec );
97
+    void selected( const TQString& _name, const TQString& _exec, const  TQString& _desktopPath );
98
+    void highlighted( const TQString& _name, const  TQString& _exec, const  TQString& _desktopPath );
97 99
 };
98 100
 
99 101
 /* ------------------------------------------------------------------------- */

Loading…
Cancel
Save