[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [PATCH] Re: [RFC long] Opening files from different applications
From: Roger Larsson <roger.larsson () norran ! net>
Date: 2003-07-25 1:41:07
[Download RAW message or body]
On Thursday 24 July 2003 12.11, Waldo Bastian wrote:
> On Thursday 24 July 2003 02:35, Roger Larsson wrote:
> > Hi all,
> >
> > Have you ever been hit by a MIME type related bug?
> > I have, they are among the most common bugs that I run into when using
> > KDE. And worse - they may lead to really strange problems...
> > Especially when applications (konqueror, gideon) makes silent overrides!
> > This is mostly to trigger some thinking in large - I will file additional
> > bug reports / wishes for the specific issues later.
>
> I think a lot of the text:plain related issues can be solved with the new
> isAlso property of mimetypes.
>
> E.g. applications such as kword, kate and khtml shouldn't check for
> mimetype == text/plain but should check for mimetype.isAlso(text/plain)
> instead. That way they will suddenly understand that they can open
> application/x-python just fine. (Assuming application/x-python has an
> is-also-text/plain property)
But that only solves the problem when you already is executing the application
code.
But the application/viewer won't show up as choice in Open With, you have to
select Other... and browse to the application - the user has to know that the
application can open a specific filetype...
Try this:
# echo "Test" > test.latex
or
# echo "Test" > test.url
Now try to open it in different ways - thumbnail view is the only part that
gets it right.
None of kwrite, kate, kword offer its help.
For me khexedit does (I have it associated with MIME type "all/allfiles")
Something is missing from the .desktop files not in the application source.
To take a specific example - gideon
What would be needed in the .desktop system to be able to remove the
hardcoded mimeinfo?
Hmm... I might need to repeat why hardcoded bindings is bad even if
they were using isAlso(text/plain) even if it is much better than the
current code. Suppose I had developed a new python specific editor plug-in.
How would I configure it - application/x-python naturally...
But that will not work because gideon sees that application/x-python
isAlso(text/plain) and opens with the default editor for text/plain...
If I know this then I can configure my really python specific editor for all
text/plain... even if it is not even decent at edition text/x-csrc files...
Today this happens (when bug is corrected and isAlso is used)
if "application/x-python".isAlso("text/plain") {
open with plug-in associated with "text/plain" unless
gideon is configured with a application specific
"EmbeddedKTextEditor" then try to use that.
I added a patch for gideon that uses the new isAlso property
(compiles, not tested, it is late...)
Note (this feature not a bug): if you try to open a application/x-python and
have a EmbeddedKTextEditor defined, then it will only be used if either:
* There are no editor defined for application/x-python (then check the parent)
* The EmbeddedKTextEditor is defined for application/x-python
Note: most mime descriptors are lacking the isAlso property...
/RogerL
PS
Shouldn't KMimeType::parentMimeType() return a KMimeType::Ptr?
Atleast rename the current to parentMimeName()...
DS
--
Roger Larsson
Skellefteċ
Sweden
["partcontroller.cpp.patch" (text/x-diff)]
Index: partcontroller.cpp
===================================================================
RCS file: /home/kde/kdevelop/src/partcontroller.cpp,v
retrieving revision 1.93
diff -u -3 -p -c -r1.93 partcontroller.cpp
cvs server: conflicting specifications of output style
*** partcontroller.cpp 17 Jul 2003 22:01:49 -0000 1.93
--- partcontroller.cpp 25 Jul 2003 00:59:03 -0000
*************** void PartController::editDocument(const
*** 235,262 ****
QString preferred, className;
! QString mimeType, encoding;
if (m_presetEncoding.isNull())
! mimeType = KMimeType::findByURL(url)->name();
else {
! mimeType = "text/plain";
encoding = m_presetEncoding;
m_presetEncoding = QString::null;
}
! kdDebug(9000) << "mimeType = " << mimeType << endl;
! if (mimeType.startsWith("text/")
! || mimeType == "application/x-zerosize"
! || mimeType == "application/x-desktop"
! || mimeType == "application/x-kdevelop" || mimeType == \
"application/x-kdevelop-project"
! || mimeType == "image/x-xpm"
! || mimeType == "application/x-perl")
{
- mimeType = "text/plain";
kapp->config()->setGroup("Editor");
preferred = kapp->config()->readPathEntry("EmbeddedKTextEditor");
! } else if( mimeType.startsWith("inode/") ){
return;
}
--- 235,260 ----
QString preferred, className;
! KMimeType::Ptr mimeType; // ->name()
! QString encoding;
if (m_presetEncoding.isNull())
! mimeType = KMimeType::findByURL(url);
else {
! mimeType = KMimeType::mimeType("text/plain");
encoding = m_presetEncoding;
m_presetEncoding = QString::null;
}
! kdDebug(9000) << "mimeType = " << mimeType->name() << endl;
! if ( mimeType->is("text/plain") )
! // This is assumed to cover:
! // application/x-zerosize, application/x-desktop, application/x-kdevelop,
! // application/x-kdevelop-project, image/x-xpm, application/x-perl, ...
{
kapp->config()->setGroup("Editor");
preferred = kapp->config()->readPathEntry("EmbeddedKTextEditor");
! } else if( mimeType->name().startsWith("inode/") ){
return;
}
*************** void PartController::editDocument(const
*** 269,275 ****
QString classnames[] = {"KTextEditor::Document", "KParts::ReadWritePart", \
"KParts::ReadOnlyPart"}; for (uint i=0; i<3; ++i)
{
! factory = findPartFactory(mimeType, services[i], preferred);
if (factory)
{
className = classnames[i];
--- 267,273 ----
QString classnames[] = {"KTextEditor::Document", "KParts::ReadWritePart", \
"KParts::ReadOnlyPart"}; for (uint i=0; i<3; ++i)
{
! factory = findPartFactory(mimeType->name(), services[i], preferred);
if (factory)
{
className = classnames[i];
*************** void PartController::editDocument(const
*** 295,301 ****
if (extension && !encoding.isNull())
{
KParts::URLArgs args;
! args.serviceType = mimeType + ";" + encoding;
extension->setURLArgs(args);
}
part->openURL(url);
--- 293,299 ----
if (extension && !encoding.isNull())
{
KParts::URLArgs args;
! args.serviceType = mimeType->name() + ";" + encoding;
extension->setURLArgs(args);
}
part->openURL(url);
*************** void PartController::editDocument(const
*** 307,313 ****
EditorProxy::getInstance()->setLineNumber(part, lineNum, col);
}
else
! KRun::runURL(url, mimeType);
}
--- 305,311 ----
EditorProxy::getInstance()->setLineNumber(part, lineNum, col);
}
else
! KRun::runURL(url, mimeType->name());
}
*************** void PartController::showDocument(const
*** 317,323 ****
KURL docUrl(fixedPath);
kdDebug(9000) << "SHOW: " << docUrl.url() << " context=" << context << endl;
! if ( docUrl.isLocalFile() && KMimeType::findByURL(docUrl)->name() != "text/html" \
) { // a link in a html-file pointed to a local text file - display
// it in the editor instead of a html-view to avoid uglyness
editDocument( docUrl );
--- 315,321 ----
KURL docUrl(fixedPath);
kdDebug(9000) << "SHOW: " << docUrl.url() << " context=" << context << endl;
! if ( docUrl.isLocalFile() && !KMimeType::findByURL(docUrl)->is("text/html") ) { \
// BUG? Note the not (!) // a link in a html-file pointed to a local text file - \
display // it in the editor instead of a html-view to avoid uglyness
editDocument( docUrl );
*************** DocumentationPart *PartController::findD
*** 361,389 ****
return 0;
}
!
! KParts::Factory *PartController::findPartFactory(const QString &mimeType, const \
QString &partType, const QString &preferredName) {
! KTrader::OfferList offers = KTrader::self()->query(mimeType, QString("'%1' in \
ServiceTypes").arg(partType));
! if (offers.count() > 0)
! {
! KService::Ptr ptr = 0;
! // if there is a preferred plugin we'll take it
! if ( !preferredName.isEmpty() ) {
! KTrader::OfferList::Iterator it;
! for (it = offers.begin(); it != offers.end(); ++it) {
! if ((*it)->name() == preferredName) {
! ptr = (*it);
! }
}
! }
! // else we just take the first in the list
! if ( !ptr ) {
! ptr = offers.first();
! }
! return static_cast<KParts::Factory*>(KLibLoader::self()->factory(QFile::encodeName(ptr->library())));
! }
return 0;
}
--- 359,394 ----
return 0;
}
! // Could be moved to KTrader::
! // but first parameter should really be KMimeType::Ptr
! KParts::Factory *PartController::findPartFactory(const QString &cMimeType, const \
QString &partType, const QString &preferredName) {
! QString &mimeType = cMimeType;
! do {
! KTrader::OfferList offers = KTrader::self()->query(mimeType, QString("'%1' in \
ServiceTypes").arg(partType));
!
! if (offers.count() > 0)
! {
! KService::Ptr ptr = 0;
! // if there is a preferred plugin we'll take it
! if ( !preferredName.isEmpty() ) {
! KTrader::OfferList::Iterator it;
! for (it = offers.begin(); it != offers.end(); ++it) {
! if ((*it)->name() == preferredName) {
! ptr = (*it);
! }
! }
! }
! // else we just take the first in the list
! if ( !ptr ) {
! ptr = offers.first();
! }
! return static_cast<KParts::Factory*>(KLibLoader::self()->factory(QFile::encodeName(ptr->library())));
}
!
! mimeType = KMimeType::mimeType(mimeType)->parentMimeType(); // DESIGN ISSUE: \
shouldn't parentMimeType return a KMimeType::Ptr?
! } while (!mimeType.isNull());
return 0;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic